You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Chart新增列时如何修改文本颜色?已尝试annotations.style不生效

你现在的配置不生效,分两种常见场景对应修改即可:

场景1:你要修改的是数据点旁的注释文字

你缺了两个必要配置:

  • 首先要在数据表中添加对应系列的annotation角色列,示例如下:
let dataTemperatures = google.visualization.arrayToDataTable([]);
dataTemperatures.addColumn('datetime', 'Date');
dataTemperatures.addColumn('number', 'External Temperature');
// 给第一个温度系列添加注释列
dataTemperatures.addColumn({type: 'string', role: 'annotation'});
dataTemperatures.addColumn('number', 'Dew Point');
// 如果也要给露点系列加注释,再加一个annotation列
// dataTemperatures.addColumn({type: 'string', role: 'annotation'});
  • 其次补全annotations配置确保生效:
annotations: {
   textStyle: {
       color: 'white',
       auraColor: 'none' // 可选,取消默认的文字半透明背景光晕
   },
   alwaysOutside: true // 可选,强制注释显示在数据点外侧,避免被线条遮挡
}

场景2:你要修改的是右上角图例的文字颜色

你用错了配置项,annotations是数据注释的配置,和图例无关,新增legend配置即可:

let temperature_options = {
    backgroundColor: chartBackgroundColor,
    titleTextStyle: {
        color: textChartColor,
        fontName: fontNameChart
    },
    // 新增图例配置
    legend: {
        textStyle: {
            color: 'white',
            fontName: fontNameChart
        }
    },
    // 剩下的原有配置保持不变即可
    hAxis: {
        textStyle: { color: textChartColor },
    },
    vAxis: {
        title: "Temperatures (°C)",
        titleTextStyle: {
            color: textChartColor,
            fontName: fontNameChart
        },
        textStyle: { color: textChartColor },
    },
    series: {
        0: { type: 'line', color: '#1CACDC' },
        1: { type: 'line', color: '#00ffff'  }
    }
};

内容的提问来源于stack exchange,提问作者Mihail

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 10:39:01