2

I've read several Threads here on d3.js and JSON, I could not fix my problem though.

Please see the picture attached. I'm working with Vaadin and integrated d3.js into my project. I now owuld like to display a forced graph with d3.js, using a local graph.json file.

All code works - except accessing the .json file. The webapplication/website is displayed correctly, but the graph is empty/not there. I assume the error lays somewhere here:

d3.json("graph.json", function(error, graph) {...}

please see picture here

I'd appreciate any help. (inb4 new to javascript)

SuperUser01
  • 199
  • 1
  • 13
  • Do you get any error messages? – Lars Kotthoff May 15 '14 at 14:34
  • Firebug gives me an error in line 80: TypeError: graph is undefined: .nodes(graph.nodes) – SuperUser01 May 15 '14 at 14:40
  • What does the `error` variable contain? – Lars Kotthoff May 15 '14 at 14:49
  • Don't know exactly what you mean. I don't see a field 'error variable'. //how to check error variable? – SuperUser01 May 15 '14 at 15:02
  • You are declaring `function(error, graph)` as your callback and accessing `graph` inside it. `error` contains any errors, which you should check to find out what's going on. – Lars Kotthoff May 15 '14 at 15:07
  • I assume this is what you mean: http://i57.tinypic.com/zxkxsw.png – SuperUser01 May 15 '14 at 18:36
  • That seems to suggest that your file isn't valid JSON. – Lars Kotthoff May 15 '14 at 20:05
  • My JSON file looks exactly like the JSON used here: http://bl.ocks.org/mbostock/3750558 - is that not valid? – SuperUser01 May 15 '14 at 20:33
  • Well that one is fine, but the invalid character error you're getting suggests that maybe something went wrong when downloading the file? I can only guess without a reproducible example. – Lars Kotthoff May 15 '14 at 20:54
  • Yeah that's my guess too, somehow the JSON file isn't loaded or can't be read, though its in the same directory and valid JSON. – SuperUser01 May 16 '14 at 14:13
  • "same" directory is a relative term. in relation to where code from vaadin is delivered and where your conext is mapped etc. check your network-tab in your web debuggin tool of choice (firebug, inspector, ...) and see if and where the graph.json is attemted to load from. either your container does not send the file (404 error) because it's not there, where you app thinks it "relative" to or it might be a problem of a wrong mimetype. – cfrick May 18 '14 at 13:26
  • May be also check your access log files of the container for any "404" errors. That should indicate on the server side which actual URLs the d3.json call tries to access. – miw Dec 11 '14 at 17:53
  • what version of vaadin and d3.js did you use? – bovino Marcelo Bezerra Feb 21 '15 at 02:39

0 Answers0