dc.js更改Choropleth映射中未定义数据的默认颜色 [英] dc.js Change default color for undefined data in choropleth map
问题描述
我正在使用dc.js和 dc.geoChoroplethChart()
来创建一个choropleth映射.以前使用 colorCalculator()
,我可以为空数据设置默认颜色.
I'm using dc.js for a choropleth map with dc.geoChoroplethChart()
. Previously with colorCalculator()
, I can set the default color for null data.
chart.colors(colorScale)
.colorCalculator(
function (d) {
return d === undefined ? '#ddd' : zipChart.colors()(d);
})
日志表明 colorMixin.colorCalculator
已被弃用,并告诉我改用 colorMixin.colors
和 colorMixin.colorAccessor
.我尝试了一下:
The log indicates colorMixin.colorCalculator
has been deprecated and tell me to use colorMixin.colors
and colorMixin.colorAccessor
instead.
I gave it a try:
chart.colors(colorScale)
.colorAccessor(function (d) {return d;})
该地图仍然有效,但是未定义数据的默认颜色现在为黑色.只有几个文档.如何在没有 colorCalculator
的情况下进行更改?
The map still works but the default color for undefined data is now black. There is only a few documentation. How can I change it like without colorCalculator
?
推荐答案
不推荐使用 colorCalculator
函数是一个错误,警告将很快删除.
Deprecating colorCalculator
function was a mistake and the warning will be removed soon.
https://github.com/dc-js/dc.js/issues/1493
我不喜欢函数的实现方式,当时我认为scale可以完成函数可以完成的所有工作,但是为这种事情编写函数更容易.
I don't like the way the function was implemented, and at the time I thought that scales can do everything that a function can do, but it is simply easier to write a function for this kind of thing.
有时候,特殊情况是处理规则异常的最佳方法!
Sometimes a special case is the best way to deal with an exception to the rule!
Alternately, if you are using a continuous or ordinal color scale, you may be able to use .unknown() which is a cleaner solution.
这篇关于dc.js更改Choropleth映射中未定义数据的默认颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!