d3.js & json - simple sample code?

前端 未结 2 860
故里飘歌
故里飘歌 2020-12-13 04:31

There are some examples to get data from external json file in d3.js. But these samples do not show the json, so I really want to see how it works.

I have this json

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 05:00

    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:

    
    

    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.

提交回复
热议问题