d3.js - adding class names to arcs from data in d3.layout.pie() -
i'm creating pie chart json file. wonder if there way can take names json file , assign them class names of arcs created d3.layout.pie().
here example created: http://blockbuilder.org/jinlong25/532d889e01d02cef2d24
essentially, want last line of code below:
var data = [ { 'name': 'apple', 'value': 250 }, { 'name': 'banana', 'value': 100 }, { 'name': 'orange', 'value': 150 } ]; var arcs = svg.selectall('g.arc') .data(pie(data.map(function(d) { return d.value; }))) .enter().append('g') .attr('transform', 'translate(70, 70)') .attr('class', function(d) { return d.name; };
but since data has been transformed pie(), wonder if there anyway add class names data generated pie().
thanks!
some d3 layouts mutate original dataset others create new dataset (like voronoi). in cases, can use array position original dataset when working new dataset. example:
var arcs = svg.selectall('g.arc') .data(pie(data.map(function(d) { return d.value; }))) .enter().append('g') .attr('transform', 'translate(70, 70)') .attr('class', function(d,i) { return data[i].name; };
Comments
Post a Comment