google / charts

https://pub.dev/packages/charts_flutter
Apache License 2.0
2.81k stars 1.24k forks source link

Auto Label Donut Pie chart - not showing same values. #409

Open SubashManian opened 4 years ago

SubashManian commented 4 years ago

we are passing same Linear sales value with different color. but it not showing the both the values with different color. in this below code. i send the value of
new LinearSales(10,Colors.blue), new LinearSales(10,Colors.yellow), but it shows only the blue color in pie chart another color(yellow) is missing.

static List<charts.Series<dynamic, int>> _createSampleData(List data) { print(data); var chartList = [ new LinearSales(50,Colors.red), new LinearSales(35,Colors.green), new LinearSales(10,Colors.blue), new LinearSales(10,Colors.yellow), new LinearSales(25,Colors.grey), ];

return [
  new charts.Series<dynamic, int>(
    id: 'Sales',
    domainFn: (dynamic sales, _) => sales.weight,
    measureFn: (dynamic sales, _) => sales.weight,
    colorFn: (dynamic sales, _) => sales.color,
    data: chartList,
  )
];

}

erf commented 4 years ago

try return a another value for domainFn

PatrickVanRietschoten commented 3 years ago

Hi!

We ran into the same issue, our return value for the domain function was the same as the return value for the measure function.

If we have two parts of the pie that have the same value, their domain is no longer unique. So this makes sense.

Changing the return value for the domain function to the index (second parameter, '_' in the example) was enough to fix this issue for us.

Notice that this is actually not a bug in charts_flutter, but just a misuse of the library.