javascript - Drawing pie charts with D3, using JSon -


i'm drawing pie chart d3. data fetched db. sample json given below. chart should have sla compliance legend , pie chart should drawn sla compliance's values(here 100), every month. legend coming fine. here, 'sla compliance' label changes different charts when other radio buttons/drop down clicked. on printing values in console, found when var pie called, value in coming undefined. chart not getting displayed. can me out.

sample json:

[  {month:"nov-11", 'sla compliance':100},{month:"dec-11", 'sla compliance':100},   {month:"jan-12", 'sla compliance':100}, {month:"feb-12", 'sla compliance':100},   {month:"mar-12", 'sla compliance':100}, {month:"apr-12", 'sla compliance':100 ] 

code:

function drawpiechart3(xdata,data,svg,index,selectedindex){     var width = 400,          height = 100,         radius = math.min(width, height) / 2;      var color = d3.scale.category20();      var arc = d3.svg.arc()         .outerradius(radius - 10)         .innerradius(0);      var pie=d3.layout.pie()         .sort(null)         .value(function(d) { return d.value; });      var temp= d3.keys(data[0]).filter(function(key) { return key !== "month"; })     color.domain(d3.keys(data[0]).filter(function(key) { return key !== "month"; }));       data.foreach(function(d) {         d.month=d.month         d.pievalue = temp.map(function(name) {               return {name: name, value: +d[name]}; });       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.month);           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.month; });       //legend portion      alert("11. in legend portion")     var mylegend = svg.selectall(".mylegend")         .data(temp)         .enter().append("g")         .attr("class", "legend")         .attr("transform", function(d, i) { return "translate(0," + (legentcount+i+1) * 20 + ")"; });     mylegend.append("rect")         .attr("x", width+40)         .attr("width", 18)         .attr("height", 18)         .style("fill", color);     mylegend.append("text")         .attr("x", width+60)         .attr("y", 9)         .attr("dy", ".35em")         .style("text-anchor", "start")         .text(function(d) { return d; });     } 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -