I have nested arrays in my json data, but I don't know how to call them in the d3 (beginner).
In the example below, I am trying to build an SVG bar chart, using data from the "January" array, nested in the "meals" array in Json.
The Json looks like this:
{
"meals":[
{"january":[
{},{}
]},
{"february":[
{},{}
]},
{"march":[
{},{}
]},
}
And the d3 code looks like this. "chart" takes the user input of a drop down menu. In this case, it basically returns "meals":
var chart = selection.options[selection.selectedIndex].id;
var dataset = data[chart];
var svg = d3.select ("body")
.append ("svg")
.attr("width", w)
.attr("height", svgHeight+30);
svg.selectAll("rect")
.data(dataset.january) //***HERE is where I'm having trouble***
.enter()
.append("rect")
data.meals
is an array. Hence you would have to access it withdataset[0], dataset[1], ...
. However, since each of the objects only contains one property, you might wan to use an object instead of an array of objects. – Felix Kling Jul 9 at 20:12