在点图波动中实施清单

时间:2019-01-04 09:48:17

标签: arrays list charts flutter point

您能告诉我们这段代码的区别吗?

final installmentList = [];
for (var i = 0; i < installment.length; i++) {
    installmentList.add(new LinearStatistic(i, installment[i].count));
}

来自此代码:

final data = [
    new LinearStatistic(0, 5),
    new LinearStatistic(1, 25),
    new LinearStatistic(2, 100),
    new LinearStatistic(3, 75),
];

当我调试并使用'data'变量时,会调用return语句,但是当我使用'instalmentList'变量时,不会被调用。

return [
    new charts.Series<LinearStatistic, int>(
        id: 'Sales',
        colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
        domainFn: (LinearStatistic sales, _) => sales.position,
        measureFn: (LinearStatistic sales, _) => sales.count,
        data: data,
        )
    ];
}

2 个答案:

答案 0 :(得分:1)

static List<charts.Series<LinearSales, int>> _createSampleData() {
// final data = [
//   new LinearSales(0, 5),
//   new LinearSales(1, 25),
//   new LinearSales(2, 100),
//   new LinearSales(3, 75),
// ];
List installment = [5, 10, 4, 22, 12];
final List installmentList = <LinearSales>[];
for (var i = 0; i < installment.length; i++) {
  installmentList.add(new LinearSales(i, installment[i]));
}
return [
  new charts.Series<LinearSales, int>(
    id: 'Sales',
    colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
    domainFn: (LinearSales sales, _) => sales.year,
    measureFn: (LinearSales sales, _) => sales.sales,
    data: installmentList,
  )
];}

使用此代码作为参考,这是我final List installmentList = <LinearSales>[];所做的更改

Here is the Result

答案 1 :(得分:0)

我使用

final installmentList = [new LinearStatistic(0, 0)];

用于声明数组。谢谢大家