Vanya Rachel
Vanya Rachel

Reputation: 1403

Implement List in Point Chart Flutter

Can you tell the difference of this code:

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

from this code:

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

When I debug and use the 'data' variable, the return statement is called, but when I use the 'instalmentList' variable, it's not getting called.

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

Upvotes: 0

Views: 564

Answers (2)

Vanya Rachel
Vanya Rachel

Reputation: 1403

I use

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

for declare the array. thanks guys

Upvotes: 0

SUMANT RAJ
SUMANT RAJ

Reputation: 64

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

Use this code as reference this is the change I did final List installmentList = <LinearSales>[];

Here is the Result

Upvotes: 1

Related Questions