Flutter - JSON and Time Series Charts

后端 未结 2 1983
攒了一身酷
攒了一身酷 2021-01-14 19:48

I am trying to display some data in a time-series chart, I found an example \"https://google.github.io/charts/flutter/example/time_series_charts/simple.html\" but the data i

2条回答
  •  走了就别回头了
    2021-01-14 20:21

    The first thing to do is to refactor TimeSeriesSales so that it makes sense in your application, for example:

    class TimeSeriesPrice {
      final DateTime time;
      final double price;
      TimeSeriesSales(this.time, this.price);
    }
    

    Next, you need to build data.

    List data = [];
    // populate data with a list of dates and prices from the json
    for (Map m in dataJSON) {
      data.add(TimeSeriesPrice(m['date'], m['price']);
    }
    var series = ... 
    

    You don't give an example of the json format, so this is a guess. (You are likely to have to parse the json string date into a Dart DateTime.)

提交回复
热议问题