D3 json stock chart not displaying

前端 未结 1 739
我寻月下人不归
我寻月下人不归 2020-12-20 10:36

Can\'t seem to properly fetch the data from JSON. My chart is not even able to be displayed. Any ideas on how i can fix this?

    

        
相关标签:
1条回答
  • 2020-12-20 10:41

    d3.json does not accept an accessor (or row) function. It has to be just:

    d3.json(url[, callback])

    In your code:

    d3.json("bboList.json", function(d) {
        d.timeStr = parseTime(d.timeStr);
        d.bid = +d.bid;
        return d;
    }, function(error, data) {
        if (error) throw error;
        //...
    });
    

    Everything between the URL and function(error, data) is the row function.

    Solution: remove it, and coerce the values to numbers and dates using a forEach:

    d3.json("bboList.json", function(error, data) {
        if (error) throw error;
    
        data.forEach(d => {
            d.timeStr = parseTime(d.timeStr);
            d.bid = +d.bid;
        });
    
        /...
    });
    
    0 讨论(0)
提交回复
热议问题