Is it possible to load csv data to nvd3 library?

被刻印的时光 ゝ 提交于 2019-12-01 08:37:31

Finally I got the error on my code. The examples from NVD3.js load the v2 file from D3.js. When we use the 2.x versions from D3 we've to load external data with the next code:

d3.csv("weather.csv", function(data) {
    data.forEach(function(d) {
        d.date = parseDate(d.Hour);
        d.T = +d.T;
    })
});

After v3 update, this thing changed and appears the error argument, and insinde the .csv function we can control the error case.

d3.csv("weather.csv", function(error, data) {
    data.forEach(function(d) {
        d.date = parseDate(d.Hour);
        d.T = +d.T;
    });
});

Here you can see this changes explained by Mike Bostock, the creator of D3.js

You can use all the methods for loading data available in D3 also with nvd3. This example uses the d3.json function to load data. You can simply replace that with d3.csv and add your processing of the data.

I've looked into a few nvd3 charts at work.

Basically I convert my CSV into a JSON structure so it could be passed into the structure required by the nvd3 libraries.

I may be wrong, but you could always tinker around the code as you need it, to fit your purpose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!