javascript - D3 Targeting/Control Over Specific Arcs -
i trying target individual arcs in inner donut. want able have control on each arc(14 of them) , change colors accordingly. want have 2 colors, either gray or lime green. 2-week progress checker. if user participates 7 of 14 days want show 7 green 7 grey, etc.
here codepen it. thank in advance.
$(function(){ var tooltip = d3.select(".tooltip"); var $container = $('.chart-container'), τ = 2 * math.pi, width = $container.width(), height = $container.height(), innerradius = math.min(width,height)/4, //innerradius = (outerradius/4)*3, fontsize = (math.min(width,height)/4); var dataset = { days: [1,1,1,1,1,1,1,1,1,1,1,1,1,1], progress: [1] }; var participation = 100; var color = d3.scale.ordinal() .range(["#7eba4a"]); // create donut pie chart layout var pie = d3.layout.pie() .sort(null); // determine size of arcs var arc = d3.svg.arc(); // append svg attributes , append g svg var svg = d3.select('.chart-container').append("svg") .attr("width", '100%') .attr("height", '100%') .attr('viewbox','0 0 '+math.min(width,height) +' '+math.min(width,height) ) .attr('preserveaspectratio','xminymin') .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); var gs = svg.selectall("g").data(d3.values(dataset)).enter().append("g").attr("class", "arc"); var path = gs.selectall("path") .data(function(d) { return pie(d); }) .enter().append("path") .attr("fill", function(d, i) { return color(i); }) .attr("d", function(d, i, j) { return arc.innerradius(innerradius+(20*j)).outerradius(innerradius+20+(20*j))(d); }) .attr("class", function(d, i, j) { if (i>=participation && j<1) return "passed" ; }) // append text inner circle svg.append("text") .attr("dy", "0.5em") .style("text-anchor", "middle") .attr("class", "inner-circle") .attr("fill", "#36454f") .text(function(d) { return "100%"; }); });
i have changed data format little bit simplify :
var daysprogress = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
1 represents day participated , 0 not participated.
here modified codepen (displays green if day partcipated, grey if not, total percentage in center):
Comments
Post a Comment