I would like to be able to filter csv data for use in a series of dynamic pie charts. (That is, the user will be presented with an initial pie chart, and will be able to click on a specific pie wedge/category to pull up another pie chart showing details for that category).
This is the relevant code, to be called within an "update" function with the "selected" variable as input:
d3.csv("budget.csv", function(i,data) {
var csv = data.filter(function(row) {
return row["category"] == selected});
var g = revenue.selectAll(".arc")
.data(pie(csv))
.enter().append("g")
.attr("class", "arc");
g.append("path")
.attr("d", arc)
//This doesn't work
.style("fill", function(d) { return color(d.csv.name); });
Color, arc, and pie were previously (successfully) defined with scale.ordinal, svg.arc, and layout.pie.
The above code nearly works -- but doesn't get the fill color of the pie pieces right. When I use d.data.name in the last line (see below), the code works fine. Can someone please explain to me why?
//This works
.style("fill", function(d) { return color(d.data.name); });
It probably goes without saying, but the usual caveats [new to d3] and apologies [sorry if this is obvious] apply. Thanks! Anna