1

I am trying to add another line in the time series chart. And currently I did not find anyway to do this. I am using chart_flutter dependencies.

Here is my chart code look like:

charts.TimeSeriesChart(
                  series,
                  animate: true,
                  defaultRenderer: charts.LineRendererConfig(
                    includeArea: true,
                    includeLine: true,
                  ),
                  dateTimeFactory: const charts.LocalDateTimeFactory(),
                  behaviors: [
                    charts.PanAndZoomBehavior(),
                    charts.SeriesLegend(
                      position: charts.BehaviorPosition.top,
                      horizontalFirst: false,
                      cellPadding: EdgeInsets.only(left: 80, top: 10, bottom: 4.0),
                    ),
                    charts.SelectNearest(
                      eventTrigger: charts.SelectionTrigger.tap
                    ),
                    charts.LinePointHighlighter(
                      symbolRenderer: CustomCircleSymbolRenderer(size: size),
                    ),
                  ],
                  selectionModels: [
                    charts.SelectionModelConfig(
                    type: charts.SelectionModelType.info,
                    changedListener: (charts.SelectionModel model) {
                      if(model.hasDatumSelection) {
                        final tankVolumeValue = model.selectedSeries[0].measureFn(model.selectedDatum[0].index).round();
                        final dateValue = model.selectedSeries[0].domainFn(model.selectedDatum[0].index);
                        CustomCircleSymbolRenderer.value = '$dateValue \n $tankVolumeValue';
                    }
                  })
                ]),

Any idea on how to add another line is welcome.

1 Answer 1

2

The answer above is simply that you can add more data in the variable that hold the data. Like below:

charts.Series(
          id: 'Tank 1',
          data: some data here,
          colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
          domainFn: (TankPing ping, _) => some data,
          measureFn: (TankPing ping, _) => some data
        ),
charts.Series(
              id: 'Tank 1',
              data: some data here,
              colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
              domainFn: (TankPing ping, _) => some data,
              measureFn: (TankPing ping, _) => some data
            )
Sign up to request clarification or add additional context in comments.

3 Comments

Can you expand on this because I cannot see how this works with this example
Hi there @AndrewThompson, sorry but this is an old Code and I did not maintain this code anymore. Probably can you refer to the doc incase they explain how to add more chart lines. Basically, all you have to do is just add charts.Series() either in loop or as a component if based on the code that I post above. Hope this help!
Thanks for replying. It had escaped me that the charts take an array of series arrays. So it is quite possible to have multiple series. I have sorted it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.