d3plus not load data from csv

233 Views Asked by At

my code:

function d3_chart() {
      // sample data array
      // instantiate d3plus
      var visualization = d3plus.viz()
        .container("#viz")  // container DIV to hold the visualization
        .data("./extra/acc.csv", {"filetype": "csv"})  // data to use with the visualization
        .type("line")       // visualization type
        .y("x")         // key to use for y-axis
        .x("timestamp")          // key to use for x-axis
        .draw()             // finally, draw the visualization!
    }

my csv:

timestamp,x,y,z
0,2019-02-28 12:20:19.631,1.072,-0.153,10.113
1,2019-02-28 12:20:19.731,1.072,-0.153,10.419
2,2019-02-28 12:20:19.831,1.072,-0.153,9.96
3,2019-02-28 12:20:19.931,1.072,-0.153,10.113
4,2019-02-28 12:20:20.031,1.072,-0.153,10.113
5,2019-02-28 12:20:20.132,1.225,-0.153,9.96
6,2019-02-28 12:20:20.231,1.225,-0.153,9.96
7,2019-02-28 12:20:20.331,1.225,-0.153,9.96
8,2019-02-28 12:20:20.431,0.919,-0.306,9.5
9,2019-02-28 12:20:20.531,0.919,0.459,9.807
10,2019-02-28 12:20:20.631,1.225,0.153,10.113
11,2019-02-28 12:20:20.731,1.379,-1.992,10.113
12,2019-02-28 12:20:20.831,1.838,-0.306,9.653
13,2019-02-28 12:20:20.931,0.153,0.766,10.113
14,2019-02-28 12:20:21.032,0.459,1.532,10.266
15,2019-02-28 12:20:21.133,1.072,0.0,9.96

I just got getting message: No Data Available

What is wrong? I don't find any example in internet with csv loading via this library

Or something know how graph chart from csv via general D3 with simple example?

1

There are 1 best solutions below

0
Coola On

d3plus seems to be using v3.5.15 of d3.js. Regardless of that, you will need to tell d3plus of how to load the data. Reading the API documentation it seems you will have to load the data using

d3plus.dataLoad(path, [formatter], [key], [callback]) as explained here.

Alternatively, you can use d3.js to parse your csv file and pass it as the data. To do this you can use the

d3.csv.parse(string[, accessor]) as provided in the d3.js CSV API.

Keep in mind in both cases you will need to format your timestamps in the correct time format (For d3.js Time Format API doc), for you to be able to use the time scales. Also at least for d3.js when the data is parsed from CSV all values are string values and hence you will need to change the type of the values using an type conversion function. You can read more about this in a great guide on how to read data by Learnjsdata (d3.js v3, or d3.js v5)

There are several examples out there for d3.js v3 on importing the data for processing which may be a better option overall. Also consider d3plus has not got a github commit in over a year so the library may not be well supported.

I hope this helps and at least gives you a start. If you need more help please leave a comment below.