Is possible to use charts_flutter to draw a real-time chart with a stream of values?

1,355

You can provide a static range for an axis like this (example is for 12-18 inclusive):

    primaryMeasureAxis: new charts.NumericAxisSpec(
      tickProviderSpec: new charts.StaticNumericTickProviderSpec(
        <charts.TickSpec<num>>[
          charts.TickSpec<num>(12),
          charts.TickSpec<num>(14),
          charts.TickSpec<num>(16),
          charts.TickSpec<num>(18),
        ],
      ),
    ),
Share:
1,355
tonidi
Author by

tonidi

Updated on December 17, 2022

Comments

  • tonidi
    tonidi over 1 year

    I haven't found an example where charts_flutter has been used using a data stream that changes over time. Is it possible to do it, or is it not the right tool? In my case, I have to show a line graph that follows the signals from microphone. Thanks

    UPDATE This is my attempt: inside my build() method I defined the chart like this:

    charts.TimeSeriesChart(
                  getStreamData(),
                  animate: true,
                  domainAxis: new charts.OrdinalAxisSpec(renderSpec: new charts.NoneRenderSpec(), showAxisLine: false),
                  primaryMeasureAxis: new charts.NumericAxisSpec(showAxisLine: false),
                  dateTimeFactory: const charts.LocalDateTimeFactory(),
    

    where my goal is consuming a data stream, and set a fixed range of measurements axis to avoid strange oscillations of the graph.

    At this time the chart successfully rebuilds, but the range on measurement axis changed every time.

    • huextrat
      huextrat over 4 years
      Yes it should be possible by notifying chart that value has been updated
    • tonidi
      tonidi over 4 years
      Ok, but the problem is that the range in the axis change depending on the new values. There is a way to fix the range?
    • Darish
      Darish over 4 years
      you can change any value, flutter will rebuild the chart for you.