Please advice D3.js for CSV data import

前端 未结 1 910
名媛妹妹
名媛妹妹 2021-01-24 13:10

I am trying to import CSV data with using D3.js.

var englishArray=\"\";
d3.csv(\"data.csv\",
    function(d) {
        return [d.value]
    },
    function(error         


        
相关标签:
1条回答
  • 2021-01-24 13:31

    Here is the example which describe how to import csv file in d3.js.

    CSV File

    Year,Make,Model,Length
    1997,Ford,E350,2.34
    2000,Mercury,Cougar,2.38
    

    JavaScript Array is

    [
      {"Year": "1997", "Make": "Ford", "Model": "E350", "Length": "2.34"},
      {"Year": "2000", "Make": "Mercury", "Model": "Cougar", "Length": "2.38"}
    ]
    

    Code to import CSV data using d3.js

    d3.csv("example.csv", function(d) {
      return {
        year: new Date(+d.Year, 0, 1), // convert "Year" column to Date
        make: d.Make,
        model: d.Model,
        length: +d.Length // convert "Length" column to number
      };
    }, function(error, rows) {
      console.log(rows);
    });
    
    0 讨论(0)
提交回复
热议问题