I am using chart_flutter plug in https://pub.dartlang.org/packages/charts_flutter and I want to change the line color of my TimeSeriesChart?
The code I have right now is this:
final chartdata = [
charts.Series<VolumePerDay, DateTime>(
id: 'Workout',
colorFn: (_, __) => charts.MaterialPalette.lime.shadeDefault,
// colorFn: (_, __) => Theme.of(context).accentColor,
domainFn: (VolumePerDay workout, _) => workout.time,
measureFn: (VolumePerDay workout, _) => workout.volume,
data: data,
)
];
return charts.TimeSeriesChart(
chartdata,
animate: false,
);
I thought that changing the colorFn property would change the color, but if I comment the line with MaterialPalette and uncomment the Theme color line, it gives me an error. How can I set the chart's line color to a color of my choice using color codes?
I am new to flutter and was also facing the same issue, So, as far as I came to know is that may be we cant use the MaterialColor
for the charts Color and So a workaround to this was to replace your charts.MaterialPalette.lime.shadeDefault
code with charts.Color.fromHex(code: '#f2f2f2')
.
This was discussed in this GitHub issue.
Dart colors can be used with ColorUtil method
color: charts.ColorUtil.fromDartColor(Colors.white),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With