简体   繁体   English

试图在印度地图上应用choropleth

[英]Trying to apply choropleth on Indian map

I am trying to apply a choropleth on the Indian map Chart. 我正在尝试在印度地图Chart上应用一个choropleth。 But not able to achieve the result - My demo 但无法达到结果- 我的演示

      var colorScale = d3.scale.quantile()
          .domain([0, buckets - 1, d3.max(json, function (d) { return json.total; })])
          .range(colors);

I can sense that the above and below codes are the cause but am unable resolve it. 我可以感觉到上面和下面的代码是原因,但无法解决。

            india.transition().duration(1000)
          .style("fill", function(d) { return colorScale(json.total); });

the colors ref where taken from bl.ocks.org/tjdecke/5558084 颜色参考取自bl.ocks.org/tjdecke/5558084

Besides the issues explained in the other answer , your color scale is wrong. 除了其他答案中说明的问题之外,您的色阶错误。 Right now it returns this array as the domain: 现在,它返回此数组作为域:

[0, 8, 9765]

Which is probably not what you want. 这可能不是您想要的。

Here is a different scale, dividing the domain in equal intervals from 0 to the maximum total : 这是一个不同的比例,将域从0到最大total等间隔划分:

var maxTotal = d3.max(json.features, function(d) {
    return d.total
});

var colorScale = d3.scale.quantile()
    .domain(d3.range(buckets).map(function(d) {
        return (d / buckets) * maxTotal
    }))
    .range(colors);

Now, this is the domain: 现在,这是域:

[0, 1085, 2170, 3255, 4340, 5425, 6510, 7595, 8680]

And here is the updated plunker: http://plnkr.co/edit/CWn1vKbzDLq1YDAu9oD7?p=preview 这是更新的插件: http ://plnkr.co/edit/CWn1vKbzDLq1YDAu9oD7?p=preview

You aren't passing the data to the quantile scale correctly. 您没有将数据正确传递到分位数标度。 And then you try to set the colors on your india variable (which is the svg) and not the paths: 然后尝试在india变量(即svg)而非路径上设置颜色:

  // pass json.features to d3.max, convert total to number
  var colorScale = d3.scale.quantile()
        .domain([0, buckets - 1, d3.max(json.features, function (d) { return +d.total; })])
        .range(colors);

  ...

  // continue chaining off path creation
  // pass total to colorScale and convert to number
  .transition().duration(1000)
  .style("fill", function(d) { 
      return colorScale(+d.total);
  });

Running code updated here . 运行代码已在此处更新。

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

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