setDataPoints method
Sets the data points stored in this graph, and redraw the graph. See also redraw.
Because the graph does not really store any kind of ordering for X values, ordering is received from iterating the data point X values, as they are stored in LinkedHashMap. The chart stores X values in this map, and as new X values are encountered from new data points and graphs, they are added to the map. LinkedHashMap stores the ordering following the order in which X values are added to the map. If you want to guarantee the ordering in any way, set labelsX in the order you want.
Implementation
void setDataPoints(String key, List<TextDataPoint> points) {
if (barLabels.isEmpty) return;
if (barLabels.isNotEmpty && !barLabels.contains(key)) return;
var labelsXSet = labelsX.isNotEmpty;
// Initialized _dataPoints in the same ordering as labelsX.
if (labelsXSet) {
// Add empty data point in some X point that is defined in labels
for (var element in labelsX) {
if (_dataPoints[element] == null) {
_dataPoints[element] = {key: null};
}
}
}
for (var dp in points) {
// If the labelsX has predefined X labels, ignore those points that are outside of defined labels.
if (labelsXSet && !labelsX.contains(dp.x)) continue;
if (_dataPoints[dp.x] == null) {
_dataPoints[dp.x] = {};
}
_dataPoints[dp.x]![key] = dp.y;
}
_setMinMaxY();
}