你能分辨出这段代码的区别吗?

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'变量时,会调用返回语句,但当我使用'installationlist'变量时,不会调用它。
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,
        )
    ];
}

最佳答案

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,
  )
];}

使用此代码作为参考这是我所做的更改
arrays - 在点图表 flutter 中实现列表-LMLPHP

关于arrays - 在点图表 flutter 中实现列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54036468/

10-09 03:36