I am able to generate pie chart and add data to it dynamically, based on user interaction.
Here is the fiddle http://jsfiddle.net/L5Q8r/
The problem I am facing is during the data removal from pie-chart. When the checkbox is unchecked, I am deleting the data from "dataset" and updating the chart.
The chart is getting updated but the previous "slice of pie" is still visible to user.
I tried adding the ".exit().remove()" but no success. Here is what I did:
var updateChart = function (dataset) {
arcs.data(pie(dataset))
.enter()
.append("path")
.attr("stroke", "white")
.attr("stroke-width", 0.8)
.attr("fill", function (d, i) {
return color(i);
})
.attr("d", arc);
arcs.data(pie(dataset)).exit().remove(); // Executing but not working
arcs.transition()
.duration(duration)
.attrTween("d", arcTween);
sliceLabel.data(pie(dataset));
sliceLabel.transition()
.duration(duration)
.attr("transform", function (d) {
return "translate(" + (arc.centroid(d)) + ")";
})
.style("fill-opacity", function (d) {
if (d.value === 0) {
return 1e-6;
} else {
return 1;
}
});
sliceLabel.data(pie(dataset))
.enter()
.append("text")
.attr("class", "arcLabel")
.attr("transform", function (d) {
return "translate(" + (arc.centroid(d)) + ")";
})
.attr("text-anchor", "middle")
.style("fill-opacity", function (d) {
if (d.value === 0) {
return 1e-6;
} else {
return 1;
}
})
.text(function (d) {
return d.data.Population;
});
sliceLabel.data(pie(dataset)).exit().remove();//executing but not working
};
Any help would be appreciated. TIA.