我正在快速创建时间序列图表,但它仅显示点的单一颜色。我想根据点的值为点分配不同的颜色。例如,值1和2是红色,而值3和4是橙色。这可能吗?@override小部件build(BuildContext context){返回新图表.TimeSeriesChart(seriesList,动画:动画,defaultRenderer:新图表.LineRendererConfig(includePoints:true,includeArea:正确,radiusPx:6),//提供一个自定义轴,以确保刻度线是整数。primaryMeasureAxis:新图表.NumericAxisSpec(tickProviderSpec:新图表.BasicNumericTickProviderSpec(requiredTickCount:11),renderSpec:新图表。GridlineRendererSpec(
// Tick and Label styling here.
labelStyle: new charts.TextStyleSpec(
fontSize: 14, // size in Pts.
color: charts.MaterialPalette.black),
// Change the line colors to match text color.
lineStyle: new charts.LineStyleSpec(
color: charts.MaterialPalette.transparent))),
domainAxis: new charts.DateTimeAxisSpec(
renderSpec: new charts.GridlineRendererSpec(
// Tick and Label styling here.
labelStyle: new charts.TextStyleSpec(
fontSize: 14, // size in Pts.
color: charts.MaterialPalette.black),
// Change the line colors to match text color.
lineStyle: new charts.LineStyleSpec(
color: charts.MaterialPalette.transparent))),
);
}
static List<charts.Series<MoodRow, DateTime>> _buildData(
List<_mood.Mood> moodEntries) {
List<MoodRow> data = new List();
for (_mood.Mood mood in moodEntries) {
data.add(new MoodRow(mood, mood.moodDate, mood.moodStatus));
}
return [
new charts.Series<MoodRow, DateTime>(
id: 'MoodStatus',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (MoodRow row, _) => row.timeStamp,
measureFn: (MoodRow row, _) => row.moodStatus,
data: data,
)
];
}
您可以使用此:
Color((math.Random().nextDouble() * 0xFFFFFF).toInt() << 0)
.withOpacity(1.0);
用您想要的数字更改math.Random()。nextDouble()