在Google图表中设置特定颜色 [英] Setting specific colors in google charts

查看:849
本文介绍了在Google图表中设置特定颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Google可视化,其中我想基于数据表中的列设置每个饼图切片/条的特定颜色。

I have Google visualization where I want to set the specific colors of each pie slice/bar based on a column in the datatable.

我有一张有投票给他们最喜欢的颜色的人数的表格:

i.e. I have a table of the number of people who voted for their favorite color:

*Input table*
id  Color   Num Votes
1  'Red'    10
2  'Blue'   100
3  'Green'  50

如何设置饼图上的颜色,使红色的切片为红色等?但是,由于数据集,我不能保证行将以一定的顺序,所以不能创建一个颜色数组。

How do I set the colors on the pie chart so that the slice for 'Red' is colored red, etc? However, due to the data set, I cannot guarantee that the rows will be in a certain order so cannot create an array of colors.

我想我需要使用格式化程序,但不能让它工作。

I think I need to use a formatter, but cannot get it to work.

 var formatter = new google.visualization.ColorFormat();
 formatter.addRange('Blue', 'Blue', 'blue', 'blue');
 formatter.format(data, 1);

提前感谢

推荐答案

轻松,

只需将其设置为 var options

它应该是这样:

var options = {'title':'Your Title',
               'width':XXX,
               'height':XXX,
               colors:['Blue', 'Blue', 'blue', 'blue']};

这篇关于在Google图表中设置特定颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆