
|
//Two months data (January and February)
List<OrdinalSales> chartData = [
OrdinalSales(DateTime(2018, 1, 1), 29),
OrdinalSales(DateTime(2018, 1, 2), 28),
OrdinalSales(DateTime(2018, 1, 3), 44),
OrdinalSales(DateTime(2018, 1, 4), 33),
OrdinalSales(DateTime(2018, 2, 1), 38),
OrdinalSales(DateTime(2018, 2, 2), 34),
OrdinalSales(DateTime(2018, 2, 3), 38),
OrdinalSales(DateTime(2018, 2, 4), 22),
];
//Drop down event in which we have grouped the data based on the selected month
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
selectedData = [];
for (int i = 0; i <chartData.length;i++){
if(newValue == 'Jan' && chartData[i].x.month == DateTime.january) {
selectedData.add(chartData[i]);
} else if(newValue == 'Feb' && chartData[i].x.month == DateTime.february) {
selectedData.add(chartData[i]);
}
}
});
},
// Chart configurations
SfCartesianChart(
//Other configurations
series: <LineSeries<OrdinalSales, DateTime>>[
LineSeries<OrdinalSales, DateTime>(
dataSource: selectedData,
//Other configurations
)
],
)
|
|
void _getData(){
for (int i = 0; i < chartData.length; i++) {
if (chartData[i].x.month == DateTime.january) {
janData.add(chartData[i]);
} else if (chartData[i].x.month == DateTime.february) {
febData.add(chartData[i]);
}
}
//Use this data source for chart
groupedData = [
GroupedData('Jan', _getGroupedYValue(janData)),
GroupedData('Feb', _getGroupedYValue(febData)),
];
}
|