I'm trying to use a nested json array to graph a multi-series chart with d3.js. I've looked a lot of places on this site and others, and while there are similar topics, I can't seem to make the syntax work with my specific problem (which is a simple one).
To make a line chart (like the one here: http://bl.ocks.org/mbostock/3883245), I can parse this JSON file:
[{"date":"1-May-12","close":58.13},{"date":"30-Apr-12","close":53.98},{"date":"27-Apr-12","close":67}]
By using this javascript syntax:
d3.json("data/data2.json", function(error, data) {
data.forEach(function(d) {
d.date = parseDate(d.date);
d.close = +d.close;
});
But what if the JSON is a nested array? For example:
{
"Stock01":[{"date":"1-May-12","close":58.13},{"date":"30-Apr-12","close":53.98},{"date":"27-Apr-12","close":67}]
"Stock02":[{"date":"1-May-12","close":28.13},{"date":"30-Apr-12","close":33.98},{"date":"27-Apr-12","close":47}]
}
I've tried options like the script below, but I'm not having any luck:
d3.json("data/data2.json", function(error, data) {
data.forEach(function(d) {
d.date = parseDate(d[0].date);
d.close = +d[0].close;
});
If anyone has advice for how to navigate a nested JSON array with the data.forEach function, I'd be grateful. Thanks in advance for any help.