【问题标题】:How to change the chart line color to custom color code value in Flutter如何在 Flutter 中将图表线条颜色更改为自定义颜色代码值
【发布时间】:2019-03-09 09:34:56
【问题描述】:

我正在使用https://pub.dartlang.org/packages/charts_flutter 中的chart_flutter 插件,我想更改我的TimeSeriesChart 的线条颜色?

我现在的代码是这样的:

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,
);

我认为更改 colorFn 属性会更改颜色,但如果我使用 MaterialPalette 注释该行并取消注释主题颜色行,它会给我一个错误。如何使用颜色代码将图表的线条颜色设置为我选择的颜色?

【问题讨论】:

  • 错误是什么?

标签: charts dart flutter


【解决方案1】:

飞镖颜色可以与 ColorUtil 方法一起使用

color: charts.ColorUtil.fromDartColor(Colors.white),

【讨论】:

    【解决方案2】:

    我是新来的颤振,也面临同样的问题,所以,据我所知,可能我们不能将MaterialColor 用于图表颜色,所以解决方法是替换你的charts.MaterialPalette.lime.shadeDefault 代码与charts.Color.fromHex(code: '#f2f2f2')

    这已在this GitHub issue 中讨论过。

    【讨论】:

      【解决方案3】:

      你可以设置

      seriesColor:charts.ColorUtil.fromDartColor(Colors.blue.shade700),

      例如。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-24
        • 1970-01-01
        • 2018-03-13
        • 2021-06-03
        • 1970-01-01
        • 2022-07-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多