【发布时间】:2014-02-26 00:52:58
【问题描述】:
我正在为一个谷歌图表创建一个自定义图例,它将显示每个系列的统计数据。我为此使用了谷歌表。因为它也是图例,所以我希望第一列具有与图表中的颜色相对应的颜色标记。但是我在 Google Charts API 中找不到任何东西,它提供了一种询问图表每个系列使用什么颜色的方法。
【问题讨论】:
标签: javascript google-visualization
我正在为一个谷歌图表创建一个自定义图例,它将显示每个系列的统计数据。我为此使用了谷歌表。因为它也是图例,所以我希望第一列具有与图表中的颜色相对应的颜色标记。但是我在 Google Charts API 中找不到任何东西,它提供了一种询问图表每个系列使用什么颜色的方法。
【问题讨论】:
标签: javascript google-visualization
图表不提供获取系列颜色的方法,但您可以指定自己的颜色(通过colors 或series.<series index>.color 选项)并在自定义图例中使用它们。
colors: ['#c038b1', '#5071c7', '#6a57b3']
或:
series: {
0: {
// set the options for the first series
color: '#c038b1'
},
1: {
// set the options for the second series
color: '#5071c7'
},
2: {
// set the options for the third series
color: '#6a57b3'
}
}
如果您想使用默认颜色,这是列表:
['#3366cc', '#dc3912', '#ff9900', '#109618', '#990099', '#0099c6', '#dd4477', '#66aa00', '#b82e2e', '#316395', '#994499', '#22aa99', '#aaaa11', '#6633cc', '#e67300', '#8b0707', '#651067', '#329262', '#5574a6', '#3b3eac', '#b77322', '#16d620', '#b91383', '#f4359e', '#9c5935', '#a9c413', '#2a778d', '#668d1c', '#bea413', '#0c5922', '#743411']
【讨论】:
你必须使用
className 或 cssClassNames 或样式
并应用您需要的任何属性,例如颜色、字体大小等
https://developers.google.com/chart/interactive/docs/gallery/table#Example
例子:
dataTable.setCell(22, 2, 15, 'Fifteen', {style: 'color:red; font-size:22px;'});
【讨论】: