以编程方式从Google Chart中获取系列的颜色

时间:2014-02-25 01:10:39

标签: javascript google-visualization

我正在为Google图表创建自定义图例,该图表将显示每个系列的统计信息。我正在使用Google表格。由于它也是图例,我希望第一列具有与图表中的颜色相对应的颜色标记。但是我在谷歌图表API中找不到任何东西,它提供了一种方法来询问图表每个系列使用的颜色。

2 个答案:

答案 0 :(得分:6)

图表不提供获取系列颜色的方法,但您可以指定自己的颜色(通过colorsseries.<series index>.color选项)并在自定义图例中使用它们。< / p>

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']

答案 1 :(得分:1)

你必须使用

  

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;'});