fix(flet-charts): ScatterChart failing to render spots with error ranges - #6885
Merged
Merged
Conversation
`ScatterChartSpot.x_error` and `y_error` were typed `Any` and handed to fl_chart's `ScatterSpot` unparsed. `Control.get` infers `FlErrorRange?` from the parameter and returns the wire value as is, so any value other than `None` failed the cast in `build()` with `type '_Map<dynamic, dynamic>' is not a subtype of type 'FlErrorRange?'`. Flutter then replaced the whole chart with its error widget, a grey box in release builds, and the message only reached Python as `page.on_error`. Add a `ChartErrorRange` value type with the `lower_by` and `upper_by` bounds of `FlErrorRange`, parse it with `parseFlErrorRange()`, and reject negative bounds in Python since `FlErrorRange` asserts they are non-negative. fl_chart draws error bars for any spot with an error range, but its default painter draws them in white, which is invisible on light backgrounds. Draw each spot's bars in the color of that spot, which is also the default in matplotlib and Plotly.
The example plots the mean period of a pendulum for each string length. Horizontal bars use `ChartErrorRange.symmetric()` for the length uncertainty, and vertical bars use an asymmetric `ChartErrorRange` that spans the fastest and slowest timing. Explicit axis bounds keep the bars inside the chart. The ScatterChart docs page shows its code.
ndonkoHenri
requested review from
FeodorFitsner
and
a balanced review from Copilot
September 24, 2026 17:56
Deploying flet-website-v2 with
|
| Latest commit: |
478d6dd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9aef15c5.flet-website-v2.pages.dev |
| Branch Preview URL: | https://fix-charts-scatter-spot-erro.flet-website-v2.pages.dev |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Range validation remains bypassable, and the regression tests claimed in the PR are absent.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Fixes ScatterChart error-range rendering and adds a typed Python API with supporting documentation and examples.
Changes:
- Adds
ChartErrorRangeand parses it into FlutterFlErrorRange. - Renders spot-colored error bars and adds an example.
- Updates documentation, changelogs, and docs task telemetry settings.
| File | Description |
|---|---|
CHANGELOG.md |
Records the user-facing fix. |
sdk/python/Taskfile.yml |
Disables Yarn telemetry for docs tasks. |
.../scatter_chart_with_error_bars/main.py |
Demonstrates error bars. |
.../scatter_chart_with_error_bars/pyproject.toml |
Defines example metadata. |
sdk/python/packages/flet-charts/CHANGELOG.md |
Records the package fix. |
flet_charts/__init__.py |
Exports ChartErrorRange. |
flet_charts/scatter_chart_spot.py |
Types and documents error ranges. |
flet_charts/types.py |
Implements ChartErrorRange. |
flutter/.../scatter_chart.dart |
Parses and renders error ranges. |
flutter/.../utils/charts.dart |
Adds the range parser. |
flutter/.../utils/scatter_chart.dart |
Adds the error-bar painter. |
website/docs/.../scatterchart.md |
Adds the example to documentation. |
website/docs/.../charterrorrange.md |
Adds API reference documentation. |
website/sidebars.yml |
Adds the new type to navigation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`nan < 0` is false, so a NaN bound passed the non-negative check. `FlErrorRange` asserts both bounds are `>= 0`, so debug builds lost the chart again. Check the documented predicate itself, so NaN raises `ValueError` like a negative bound does.
FeodorFitsner
approved these changes
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
ScatterChartSpot.x_errorandy_errorwere typedOptional[Any]and passed unparsed to fl_chart'sScatterSpot, whosexError/yErrorareFlErrorRange?.Control.get<T>infersTfrom the parameter and returns the wire value as is, so any value other thanNonefailed the cast inbuild():Flutter then replaced the whole chart with its error widget, a grey box in release builds, and the message only reached Python as
page.on_error. No value could work, so both fields could only ever beNone. It's the same defect class as #6684 and #6744.Changes
ChartErrorRangevalue type with thelower_byandupper_bybounds ofFlErrorRange(fl_chart 1.2.0), plussymmetric()andcopy(). Negative bounds raiseValueError, sinceFlErrorRangeasserts they are non-negative.x_error/y_errorare now typed with it; every non-Nonevalue crashed before, so no working code changes.parseFlErrorRange()parses both fields.errorIndicatorDataline. fl_chart already draws bars for spots with error ranges (FlErrorIndicatorData.showdefaults totrue), but its default painter is white, which is invisible on light backgrounds. Spot color is also the default in matplotlib and Plotly.ScatterChartHelperignores error ranges), so bars need explicitmin_*/max_*to stay inside the chart.scatter_chart_with_error_bars(pendulum timings: a symmetric range on x, an asymmetric fastest-to-slowest range on y), shown on the ScatterChart docs page.ChartErrorRangedocs page and sidebar entry, and changelog entries inCHANGELOG.mdand the flet-charts changelog.sdk/python/Taskfile.yml: Yarn telemetry is disabled in the docs tasks.Not in this PR: an API to style the bars (color, width, cap length) through fl_chart's
errorIndicatorData, and error ranges forLineChart/BarChart, which fl_chart also supports.Testing
Controltree reproduced the cast error before the fix and passed after it. It also checked the bar color and the parser's fallbacks.{"lower_by": 0, "upper_by": 1.5}(both bounds are always sent, zero included), and negative bounds raise.scatter_chartintegration goldens (image_for_docs,example_1) still match.dart analyze, ruff, the Python unit tests (914 passed), andcrocodocs generate.Summary by Sourcery
Fix scatter-chart error-range support and add a public API and documentation for visible error bars.
New Features:
ChartErrorRangevalue type for configuring symmetric or asymmetric scatter-plot uncertainty ranges.Bug Fixes:
ScatterChartrendering failures when spots include x- or y-axis error ranges.Enhancements:
Build:
Documentation:
ChartErrorRangeand add the error-bar example to the ScatterChart documentation.Tests: