2014-02-25 23 views
5

我正在为Google图表创建自定义图例,该图例将显示每个系列的统计信息。我为此使用Google表格。因为它也是图例,我希望第一列具有与图表中的颜色相对应的颜色标记。但我无法在Google Charts API中找到任何内容,它提供了询问图表每种系列使用何种颜色的方法。以编程方式从Google图表中获取系列的颜色

回答

6

图表不提供获取系列颜色的方法,但您可以指定自己的颜色(通过colorsseries.<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'] 
相关问题