问题
I hope y'all can help me. I am stuck trying to make a bar chart with a time series using D3 and a JSON file. My JSON file is structured like so:
{
"ProjectCode": "PRJ2.1",
"numberOfSchools": 1188,
"newSchools": 0,
"date": 2011-12
},
The y axis is supposed to show the numberOfSchools whilst the x axis is supposed to show the years passed. I used a combination of a time scale and ordinal scale for the x axis and parsed the date as so:
data.forEach(function(d) {
d.date = parseDate(d.date.toString());
d.numberOfSchools = +d.numberOfSchools;
});
I'm guessing the JSON file is not being parsed properly and have tried the solutions here and here with no luck. I'm using D3.v3. and below is my JSFiddle
http://jsfiddle.net/siyafrica/ESYE3/
回答1:
I've seen above fiddle, and understood, from that I can say give the exact location where the file is. Url of the Json File might be wrong that's why problem is raising. Read below Definition
d3.json(url[, callback])
Creates a request for the JSON file at the specified url with the mime type "application/json". If a callback is specified, the request is immediately issued with the GET method, and the callback will be invoked asynchronously when the file is loaded or the request fails; the callback is invoked with two arguments: the error, if any, and the parsed JSON. The parsed JSON is undefined if an error occurs. If no callback is specified, the returned request can be issued using xhr.get or similar, and handled using xhr.on.
Above is from GitHub--> https://github.com/mbostock/d3/wiki/Requests#d3_json
来源:https://stackoverflow.com/questions/24425252/d3-parsedate-error-cannot-read-property-foreach-of-undefined