1

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/

Community
  • 1
  • 1
Siya
  • 829
  • 4
  • 17
  • 29

1 Answers1

0

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

saikiran.vsk
  • 1,788
  • 1
  • 10
  • 11
  • The JSON file is on my local server and when I try to change the URL to the exact location (i.e. Applications/MAMP/htdocs/Visualization/Data/data.json) it gives me a 404 error. But when I leave it as is it finds the file. Also in my console I get a 200 OK notification that the file is found. – Siya Jun 26 '14 at 09:08
  • Then I could suggest you that look at your structure of data in JSON file, data has a key date and it's associated value is 2011-12 this will gives 1999, but in parseDate we are mentioning the format is different, once give value as string that is write that value in double quotes and check. Give reply still facing problem. – saikiran.vsk Jun 26 '14 at 09:23
  • I turned the date into a string like so: "1-Mar-13". And I changed the parseDate function to so: var parseDate = d3.time.format("%d-%m-%y").parse; And I still get the same error. – Siya Jun 26 '14 at 10:44
  • In your jsfiddle also we are getting the same problem, but you are saying data.json reading fine and in console you are getting 200 OK response,but I'm seeing below error GET http://fiddle.jshell.net/siyafrica/ESYE3/show/Data/data.json 404 Not Found 360ms why it is displaying?? – saikiran.vsk Jun 26 '14 at 11:40
  • I'm getting a 304 Not Modified now. – Siya Jun 26 '14 at 11:50
  • Hello @Siya, Actually I would like work in abroad, but I don't know how to get. Could you guide, how to approach.. Thanks in Adv. – saikiran.vsk Jun 26 '14 at 12:38