如何在 Google GeoChart 中使用不同的颜色
我了解如何使用 GeoChart 显示连续体数据(即温度)。
但是如何配置它来显示不同的数据集(共和、民主、独立的国家)?这可能吗?
谢谢!
I understand how to use the GeoChart to display a data that is in a continuum (i.e. temperture).
But how can you configure it to display distinct data sets (states that are republican, democratic, independent)? Is this possible?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以通过稍微调整数据并使用标签的格式化值来解决此问题。您应该可以将以下代码粘贴到此处看一个例子:
You can also solve this by massaging the data a bit and using formatted values for your labels. You should be able to paste the following code into here to see an example:
现在可以通过将分类转换为数字而不是政党名称来实现。例如:
接下来,在 colorAxis 颜色数组中包含每个政党的颜色:
以下代码将民主国家显示为蓝色,共和党显示为红色,无党派显示为绿色(数据是编造的,我不知道哪个州更喜欢哪个政党)。
只要您在 colorAxis 中列出的颜色与您用于状态的分类的数量和顺序相匹配,您就可以控制状态的颜色。
This can now be accomplished by converting your classifications to numbers instead of party names. For example:
Next include a color for each party in the colorAxis colors array:
The following code displays democratic states as blue, republicans as red and independents as green (the data is made up, I don't which states prefer which party).
As long as the colors you list in the colorAxis match the number and order of classifications you use for the states, you can control the color of the state.
你尝试过这样的事情吗?
Have you tried something like this?
此时无法通过这种方式使用GeoChart。为了实现这一点,我最终使用了 svg 地图,并通过 css 更改填充。
可以在这里找到一个很好的教程:http://blog。 Visual.ly/how-to-make-choropleth-maps-in-d3/
At this time it is not possible to use GeoChart in this way. To accomplish this I ended up using a svg map, and changing the fill via css.
A good tutorial can be found here: http://blog.visual.ly/how-to-make-choropleth-maps-in-d3/