Skip to content

Fix BarChart stack items without from_y and LineChart point animation - #7064

Merged
FeodorFitsner merged 9 commits into
mainfrom
fix/charts-stack-item-line-animation
Nov 16, 2026
Merged

FeodorFitsner merged 9 commits into
mainfrom
fix/charts-stack-item-line-animation

Conversation

@ndonkoHenri

@ndonkoHenri ndonkoHenri commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Two flet-charts bug fixes for 1.1.3, plus a small docs cleanup.

BarChart fails when a stack item has no from_y

BarChartRodStackItem.from_y was optional and defaulted to None, so leaving it out sent nothing to the client. The Dart side force-unwrapped it (getDouble("from_y")!), so building the rod threw and the whole BarChart failed:

fch.BarChartRod(to_y=9, stack_items=[fch.BarChartRodStackItem(to_y=3, color=ft.Colors.RED)])

from_y now defaults to 0 on both sides.

LineChart jumps instead of animating (flet-charts#8)

_LineChartControlState kept one List<FlSpot> per data series and refilled it in place (clear() + add()) on every update. The previous LineChartData, which fl_chart's implicit animation tweens from, referenced that same list. So the animation started from the new points and the chart jumped straight to its final state. Point edits now build a new list so the previous coordinates stay available to the tween. When a fixed-width rolling window advances over unchanged samples, the chart animates the X axis while preserving sample coordinates. This works with explicit and inferred X bounds.

Runnable examples and tests

Run one example at a time. From sdk/python, start the app on port 8550. From client on the PR branch, run fvm flutter run -d chrome to connect with the local renderer.

uv run flet run --web --port 8550 /path/to/line_chart_jump.py

Point updates with fixed axes

Click Toggle point values. The script changes only the Y values. On main, the points jump to the final shape. On this branch, they interpolate over one second.

line_chart_jump.py
import flet as ft
import flet_charts as fch

SERIES = ((2, 4, 3, 5, 2), (8, 6, 9, 7, 8))


def main(page: ft.Page):
    page.title = "LineChart animation demo"
    page.padding = 24

    points = [fch.LineChartDataPoint(x=x, y=y) for x, y in enumerate(SERIES[0])]
    chart = fch.LineChart(
        data_series=[
            fch.LineChartData(
                points=points,
                color=ft.Colors.BLUE,
                stroke_width=4,
                point=True,
            )
        ],
        min_x=-0.5,
        max_x=4.5,
        min_y=0,
        max_y=10,
        height=250,
        animation=ft.Animation(duration=1000, curve=ft.AnimationCurve.LINEAR),
        interactive=False,
        horizontal_grid_lines=fch.ChartGridLines(
            interval=2, color=ft.Colors.OUTLINE_VARIANT
        ),
    )
    current_series = 0

    def toggle_points(e: ft.Event[ft.Button]):
        nonlocal current_series
        current_series = 1 - current_series
        for point, y in zip(points, SERIES[current_series], strict=True):
            point.y = y
        chart.update()

    page.add(
        ft.Button("Toggle point values", on_click=toggle_points),
        chart,
    )


if __name__ == "__main__":
    ft.run(main)

Right-to-left scrolling with explicit X bounds

Run running_line_chart.py with the same command. It adds one sample every 500 ms and animates the eight-second window over 400 ms. The retained waveform should move left with the same sample heights.

running_line_chart.py
import asyncio
from itertools import count
from math import sin, tau

import flet as ft
import flet_charts as fch

WINDOW_SECONDS = 8
SAMPLES_PER_SECOND = 2
POINT_COUNT = WINDOW_SECONDS * SAMPLES_PER_SECOND + 1


def sample(index: int) -> fch.LineChartDataPoint:
    t = index / SAMPLES_PER_SECOND
    y = 5 + 2 * sin(tau * t / 3) + 0.6 * sin(tau * t / 1.5)
    return fch.LineChartDataPoint(x=t, y=y)


async def main(page: ft.Page):
    page.title = "Running LineChart"
    page.padding = 24

    series = fch.LineChartData(
        points=[sample(index) for index in range(POINT_COUNT)],
        color=ft.Colors.BLUE,
        stroke_width=3,
    )
    chart = fch.LineChart(
        data_series=[series],
        min_x=0,
        max_x=WINDOW_SECONDS,
        min_y=0,
        max_y=10,
        height=250,
        horizontal_grid_lines=fch.ChartGridLines(
            interval=2, color=ft.Colors.OUTLINE_VARIANT
        ),
        interactive=False,
        # Leave time for the built-in tween to finish before the next sample.
        animation=ft.Animation(duration=400, curve=ft.AnimationCurve.LINEAR),
    )
    page.add(ft.Text(f"Last {WINDOW_SECONDS} seconds", size=20), chart)

    connected = asyncio.Event()
    connected.set()

    async def scroll():
        for index in count(POINT_COUNT):
            await asyncio.sleep(1 / SAMPLES_PER_SECOND)
            await connected.wait()

            series.points.pop(0)
            series.points.append(sample(index))
            chart.min_x = series.points[0].x
            chart.max_x = series.points[-1].x
            chart.update()

    task = page.run_task(scroll)

    async def resume(_):
        connected.set()

    async def pause(_):
        connected.clear()

    async def stop(_):
        task.cancel()

    page.on_connect = resume
    page.on_disconnect = pause
    page.on_close = stop


if __name__ == "__main__":
    ft.run(main)

Declarative dashboard with inferred X bounds

The CPU, memory, and disk gauges append keyed samples every second. They use a 100 ms built-in animation and infer the X bounds from their data. Each waveform should scroll left while keeping the retained samples at the same heights. Dashboard example

uv run flet run --web --port 8550 examples/extensions/charts/line_chart/dashboard_declarative/main.py

Flutter regression tests

The tests check intermediate painted positions for rolling windows with explicit and inferred X bounds, interpolation when a point changes, and per-point visibility for above_line and below_line. I also replayed the Flet updates from all three dashboard gauges in Flutter and verified scrolling on fl_chart 1.2.0 and 1.3.1. Widget tests

Docs

Removed the "Touch ID and Face ID" note from the Permissions section of the macOS publishing page. Its :::note Title syntax doesn't render in Docusaurus 3. It also described LocalAuthentication setup, which the LocalAuthentication page already covers.

Summary by Sourcery

Fix chart rendering and animation regressions while adding regression coverage and cleaning up macOS publishing documentation.

Bug Fixes:

  • Fix BarChart rendering for stack items without an explicit starting position or color, including fallback to the parent rod color.
  • Fix LineChart updates jumping to final values by preserving previous points for animation and smoothly scrolling rolling windows with explicit or inferred X bounds.

Enhancements:

  • Improve LineChart area-line visibility handling during animated point updates.

Documentation:

  • Remove redundant macOS biometric authentication guidance from the publishing documentation.

Tests:

  • Add Flutter regression coverage for BarChart stack-item defaults, LineChart point interpolation, rolling-window scrolling, inferred bounds, large X values, and animated area-line visibility.

Chores:

  • Update flet-charts and project changelogs for the fixes.

A BarChartRodStackItem left from_y unset, so the client read a missing
value and the whole BarChart failed to render. from_y now defaults to 0
on both sides.

LineChart kept one spots list per data series and refilled it on every
update. The previous LineChartData held that same list, so the implicit
animation tweened from the new points to the new points and the chart
jumped. Each update now builds a new list (flet-charts#8).
It used a title syntax Docusaurus 3 doesn't support, so it rendered
badly, and it described LocalAuthentication setup, which the
LocalAuthentication page already covers.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@ndonkoHenri ndonkoHenri changed the title Fix BarChart stack items without from_y and LineChart point animation Fix BarChart stack items without from_y and LineChart point animation Nov 8, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: a91f9a0
Status: ✅  Deploy successful!
Preview URL: https://ec32d540.flet-website-v2.pages.dev
Branch Preview URL: https://fix-charts-stack-item-line-a.flet-website-v2.pages.dev

View logs

Set the gauge chart animation duration to 100 ms instead of disabling it.
- Slide the X axis with a dedicated controller while a rolling window
  scrolls, instead of mutating lists fl_chart is still tweening, so scrolls
  that arrive mid-animation no longer morph samples by index.
- Detect scrolling with a tolerance scaled to the magnitude of X, use
  fl_chart's own bound inference, and accept windows that only grow.
- Rebuild series only when the control changes, not on every build, and
  reuse them for touch indicators.
- Resolve above/below spot line flags by spot identity when settled, with
  a self-correcting counter during animations.
- Default a BarChartRodStackItem without a color to its rod's color, and
  type from_y as a plain number.
@FeodorFitsner
FeodorFitsner merged commit c6ed3d8 into main Nov 16, 2026
3 of 70 checks passed
@FeodorFitsner
FeodorFitsner deleted the fix/charts-stack-item-line-animation branch November 16, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants