Chr*_*ton 7 javascript google-visualization
我正在为Google Chart创建一个自定义图例,该图表将显示每个系列的统计信息.我正在使用Google表格.由于它也是图例,我希望第一列具有与图表中的颜色相对应的颜色标记.但是我在谷歌图表API中找不到任何东西,它提供了一种方法来询问图表每个系列使用的颜色.
图表不提供获取系列颜色的方法,但您可以指定自己的颜色(通过colors
或series.<series index>.color
选项)并在自定义图例中使用它们.
colors: ['#c038b1', '#5071c7', '#6a57b3']
Run Code Online (Sandbox Code Playgroud)
要么:
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'
}
}
Run Code Online (Sandbox Code Playgroud)
如果要使用默认颜色,则列表如下:
['#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']
Run Code Online (Sandbox Code Playgroud)
你必须使用
className 或 cssClassNames 或 style
并应用您需要的任何属性,例如颜色、字体大小等
https://developers.google.com/chart/interactive/docs/gallery/table#Example
例子:
dataTable.setCell(22, 2, 15, 'Fifteen', {style: 'color:red; font-size:22px;'});
Run Code Online (Sandbox Code Playgroud)