简体   繁体   English

使用Google Visualization Geochart色阶的3种颜色尺寸

[英]3 color dimensions with Google Visualization Geochart Color Scale

I have three different 'vectors' for my data. 我的数据有三个不同的“向量”。 For each row in my data, I have what percent like dogs, what percent like cats, and what percent like other pets. 对于数据中的每一行,我都有像狗一样的百分比,像猫一样的百分比以及其他宠物一样的百分比。

A  20, 40, 40
B  10, 20, 70
C  80,  0, 20
D  90, 10,  0
...

I want to use a Google Visualization Geochart to represent countries by color according to which pet they prefer. 我想使用Google Visualization Geochart根据喜欢的宠物用颜色表示国家/地区。 I would like to do that by assigning an RGB value depending on what percent of people in the country like that certain type of pet. 我想通过分配RGB值来做到这一点,具体取决于该国某类宠物的百分比。

So 100, 0, 0 would be 100% red. 因此100、0、0将是100%红色。 0, 100, 0 would be 100% green. 0、100、0将是100%绿色。 0, 0, 100 would be 100% blue. 0、0、100将是100%蓝色。 And everything in between. 介于两者之间。

If coding the colors by hand, this is easy using javascript like this . 如果手动编码颜色,则使用javascript这样的代码很容易。 The issue that I have is that every single row will have a different combination (I have very good data on pet preferences down to several decimal points), and that would require me to assign a color value for each row, and I have about 200 of them. 我的问题是,每一行都会有不同的组合(我有很好的关于宠物偏好的数据,低至几个小数点),这将要求我为每行分配一个颜色值,我大约有200其中。

While that is a last resort, I'd much rather use the gradients built-in to the Geochart to do the heavy lifting for me. 尽管这是不得已的方法,但我还是更愿意使用Geochart内置的渐变为我完成繁重的工作。

The issue is that the color-gradient allows only 2d gradients. 问题在于颜色渐变仅允许2d渐变。 I can have multiple gradients, but I cannot determine if using only 2d gradients I can represent a 3d colorspace. 我可以有多个渐变,但是我无法确定是否仅使用2d渐变就可以表示3d色彩空间。

So I could create a gradient for: 因此,我可以为以下项创建渐变:

  • Red to Green 红色到绿色
  • Green to Blue 绿色到蓝色
  • Blue to Green 蓝色到绿色

Will this cover the range of color possibilities, or will it simply give me control over the hue, but not the saturation or the brightness? 这将涵盖可能的颜色范围,还是仅让我控制色相,而不是饱和度或亮度? Is this doable, or am I just better off going with the workaround? 这可行吗,或者我只是更好地解决了吗?

I ended up doing it manually since it was significantly easier. 我结束了手动操作,因为它非常容易。 I ended up with 4 vectors for my data, so I colored them using the CMYK color model. 我最终得到了4个矢量作为数据,因此我使用CMYK颜色模型为它们着色。 For each vector, I calculated the % as a portion of either the C, M, Y, or K components of the color. 对于每个向量,我都将百分比计算为颜色的C,M,Y或K分量的一部分。

I then converted it to RGB using the following logic (pseudo-code): 然后,我使用以下逻辑(伪代码)将其转换为RGB:

C' = C * (100% - K) + K
M' = M * (100% - K) + K
Y' = Y * (100% - K) + K

R = 255 - 255 * C'
G = 255 - 255 * M'
B = 255 - 255 * Y'

I converted those to HTML color codes and tossed them in an array. 我将它们转换为HTML颜色代码,并将它们扔进一个数组中。 I then assigned a value to each row corresponding to the element in the array that colors it, and tossed it in the colorAxis.colors portion of the options. 然后,我为与该元素colorAxis.colors的数组中的元素对应的每一行分配一个值,并将其扔到选项的colorAxis.colors部分中。

The result was mind-bogglingly hideous and entirely impractical as a way of conveying information. 结果是令人难以置信的可怕,并且作为一种传达信息的方式是完全不切实际的。 Not only were the colors hideous (Cyan, Magenta, and Yellow is not a nice combination of colors), but you really couldn't tell what the heck the mix was unless you are a bonafide color expert (my audience is not). 不仅颜色令人讨厌(青色,洋红色和黄色不是很好的颜色组合),而且除非您是真正的颜色专家(我的观众不是),否则您真的无法分辨混合的含义。

Back to the drawing board it is! 回到绘图板!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM