2

I am trying to implement donut chart with multiple series (ex:2) using the d3.js library. I need to use json data as source.

Any Idea how to do this.

This is the source code, i used for donut chart:

var width = 800,
    height = 400,
    radius = Math.min(width, height) / 2;
var color = d3.scale.ordinal()
    .range(["#98abc5", "#8a89a6", "#7b6888"]);

var arc = d3.svg.arc()
    .outerRadius(radius - 70)
    .innerRadius(radius - 120);

var pie = d3.layout.pie()
    .sort(null)
    .value(function (d) { return d.Count; });

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

 var jsondata = [{ "id": 1,"age": 5, "population": 2704659 }, { "id": 2, "age": 7, "population": 4499890 }, { "id": 3, "age": 8, "population": 2159981 }];
data = jsondata;
    d3.json('talent/data', function (error, data) {
    console.log(data);
    var g = svg.selectAll(".arc")
        .data(pie(data))
      .enter().append("g")
        .attr("class", "arc");

    g.append("path")
        .attr("d", arc)
        .style("fill", function (d) { return color(d.data.Name); });

    g.append("text")
        .attr("transform", function (d) { return "translate(" + arc.centroid(d) + ")"; })
        .attr("dy", ".35em")
        .style("text-anchor", "middle")
        .text(function (d) { return d.data.Name; });
});
</script>

Multi-series donut chart like : http://www.jqplot.com/tests/pie-donut-charts.php

user2238971
  • 151
  • 1
  • 1
  • 7

0 Answers0