如何更改图表的标签颜色

Ryo*_*ota 2 charts dart flutter flutter-layout

我想更改图表的标签颜色。

我正在使用谷歌的图表库(https://github.com/google/charts)。

在此输入图像描述

Sun*_*nny 5

您可以使用更改颜色axis

var axis = charts.NumericAxisSpec(
        renderSpec: charts.GridlineRendererSpec(
            labelStyle: charts.TextStyleSpec(
                fontSize: 10, color: charts.MaterialPalette.white), //chnage white color as per your requirement.
            ));
Run Code Online (Sandbox Code Playgroud)

并在图中定义

primaryMeasureAxis: axis,
      domainAxis: axis,
Run Code Online (Sandbox Code Playgroud)

  • 谢谢您的回答!它仅适用于primaryMeasureAxis,但不适用于domainAxis,错误低于flutter:构建RawGestureDetector(状态:flutter:RawGestureDetectorState#3ed6c(手势:[tap]))抛出以下断言:flutter:类型'NumericAxisSpec'不是'AxisSpec<String>' 类型的子类型 (3认同)
  • @RyosukeYokota 如果您的域轴不是数字,您可以查看其他轴规格。对于字符串,它是 OrdinalAxisSpec。 (2认同)