【问题标题】:How to bind each arc of a pie chart with user-defined colors(for each arc)?如何将饼图的每个弧与用户定义的颜色绑定(对于每个弧)?
【发布时间】:2016-05-20 09:16:18
【问题描述】:
       color=d3.scale.ordinal().domain(dataset.label)
       .range(temp);

dataset.label 是用户将为其提供颜色要求的域(弧标签)。temp 是用户给出的值数组。

【问题讨论】:

    标签: javascript d3.js


    【解决方案1】:

    希望此代码示例对您有所帮助。

    假设,dataset.label 是数据集中的一个标签数组;其中 dataset 是一个对象数组,temp 是一个颜色代码数组。

    var  color=d3.scale.ordinal().domain(dataset.label)
           .range(temp);
    
    var g = svg.selectAll(".arc")
          .data(pie(dataset))
          .enter().append("g")
          .attr("class", "arc");
    
    g.append("path")
          .attr("d", arc)
          .style("fill", function(d) { return color(d.label); });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      • 2023-01-25
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多