Flutter-以编程方式绘制图表值

时间:2019-01-31 11:45:02

标签: charts flutter

我一直在this package的帮助下研究动态图表。当视图load时,用Date.Now()和Date.Now-7天填充输入。当我将更改为值以增加范围works时。当我将更改为值以缩小范围和搜索结果时,图表未显示新值,请查看doesn't update

List<charts.Series<TimeSeriesSales, DateTime>> seriesList;
List<TimeSeriesSales> data = [];
TextEditingController toController = new TextEditingController();
TextEditingController fromController = new TextEditingController();

ONLOAD

void initState() {
     super.initState();
     seriesList = showData();
     animate = false;
     getParcelsDetails(widget.elemento.id.toString(),fromController.text, toController.text);
}

Future<Null> getParcelsDetails(id, from, to) async {
"URL" (PSEUDOCODE)
final getBody = responseJson['body'];
setState(() {
     if (getBody != null) {
          for (Map parcelas in getBody) {
               var fecha = new DateTime.fromMillisecondsSinceEpoch(parcelas['date']);
                data.add(TimeSeriesSales(new DateTime(fecha .year, fecha .month, fecha .day, date.hour),parcelas['value']]));
});
seriesList = showData();
};

ONCLICK

onPressed: () {
     setState(() {          
     getParcelsDetails(widget.elemento.id.toString(),fromController.text, toController.text)
     .catchError((error) {
      print(error.toString());
           Messages.general('Error code', context);
          });
     });
},

 CHART DATA

 List<charts.Series<TimeSeriesSales, DateTime>> showData() {
      return [
           new charts.Series<TimeSeriesSales, DateTime>(
            id: 'Consumo',
            colorFn: (_, __) =>  charts.MaterialPalette.blue.shadeDefault,
            domainFn: (TimeSeriesSales valor, _) => valor.fecha,
            measureFn: (TimeSeriesSales valor, _) => valor.valor,
            data: data,
          ),
        ];
 }

所以问题是:为什么当范围增加时,图表显示新值,而当减小范围时图表不显示新值?

0 个答案:

没有答案