You can also use Jquery JSON calls if you're more familiar with those. Or you can even just use a script tag that references a variable being assigned to JSON, like so:

<script src="us-pres.json" type="text/javascript"></script>

where us-pres.json starts like this:

var dataset = {"state":"US",...

As long as you get the JSON into a variable (collection), d3 doesn't really care how you do it. Once it's there, you just assign it using the d3 .data(dataset) call.


Try something like this

d3.json("data.js", function(data) {

where data.js or data.json or whatever you want to call it as long as it has js content is your json file. Also try reading: All your code that uses the json data will be called from the json callback function.

Related Query

More Query from same tag