【问题标题】:dc.js bubblechart colors scale is not workingdc.js 气泡图颜色比例不起作用
【发布时间】:2016-06-22 12:32:30
【问题描述】:

我正在尝试根据特定的数据阈值为气泡图设置颜色,我的数据的域为 0 到 100。我想为值 0-40、40-60 和 > 60 显示不同的颜色。

我尝试了以下运气

.colors(["#e57275", "#94dfeb","#f6df86"])
.colorDomain(function() {
    return ["Poor", "Average","Good"]
 })
 .colorAccessor(function(d) {

    if (d.value.performance < 40) {
      return "Poor";
    }
    if (d.value.performance >= 40 && d.value.performance < 60) {
      return "Average";
    }
    if (d.value.performance >= 60) {
      return "Good";
    }
 })

这是演示问题的Plnkr

【问题讨论】:

  • 这看起来很合理,不知道为什么它不起作用。

标签: d3.js dc.js crossfilter


【解决方案1】:

只需直接指定颜色...

  .colors(["#e57275", "#94dfeb","#f6df86"])
  .colorAccessor(function(d) {
    //  alert('Lets chec' + d.performance)
    if (d.value.performance < 40) {
      return 0;
    }
    if (d.value.performance >= 40 && d.value.performance < 60) {
      return 1;
    }
    if (d.value.performance >= 60) {
      return 2;
    }
  })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多