Loading D3.js data from a simple JSON string

后端 未结 6 800
礼貌的吻别
礼貌的吻别 2020-11-28 06:29

Most of the examples in gallery load data from TSV files.

How can I convert the following to use a local json variable instead of TSV data?

d3.tsv(&quo         


        
6条回答
  •  无人及你
    2020-11-28 07:17

    for remote data.json replace :

    d3.tsv("data.tsv", function(error, data) {...}
    

    with :

    d3.json("data.json", function(error, data) {
        console.log(data); // this is your data
    });
    

    for local data:

    var myData = { {date:'2013-05-01', frequency:99},
                   {date:'2013-05-02', frequency:24} };
    
    function draw(data) {
        console.log(data); // this is your data
    }
    
    draw(myData);
    

提交回复
热议问题