d3 js - loading json without a http get

前端 未结 3 1385
无人共我
无人共我 2020-11-29 18:57

I am learning d3. There are certain ways of loading the data in d3 js. But all of them seem to make a HTTP GET. In my scenario, I already have the json data in a string. How

3条回答
  •  甜味超标
    2020-11-29 19:41

    Simply replace d3.json call with

    json = JSON.parse( myjson );
    

    IE:

    var myjson = '{"name": "flare","children": [{"name": "analytics","children": [{"name": "cluster","children": [{"name": "MergeEdge", "size": 10 }]}]}]}';
    
    // d3.json("/path/flare.json", function(json) { #delete this line
    
        json = JSON.parse( myjson ); //add this line
    
        //rendering logic here
    
    //} #delete this line
    

    UPDATE 09/2013

    Original code has changed. So varname json should be root:

    // d3.json("flare.json", function(error, root) { #delete this line
    
        root = JSON.parse( myjson ); //add this line
    
        //rendering logic here
    
    //} #delete this line
    

提交回复
热议问题