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
相关产品推荐
相关产品推荐

