当解析器不是逗号时,如何使用 d3 解析 csv 文件

How to parse a csv file with d3 when parser is not the comma

本文关键字:何使用 d3 解析 文件 csv      更新时间:2023-09-26

我正在使用感谢 d3 导入的 csv 文档。不幸的是,解析器并不是逗号,我没有找到解析器在文件架构中记录的位置......无论如何。现在,我知道我的解析器是一个分号,那么我尝试像这样使用 dsv 函数

var csvfile= d3.dsv(";", VariableWithcsvFileInside);

console.log(data);返回这个:

函数 e(n,e,i){arguments.length<3&&(i=e,e=null);var a=Cn(n,t,null==e?r:u(e),i);return a.row=function(n){return arguments.length?a.response(null==(e=n)?r:u(n)):e},a}

是否有我必须导入的脚本或我做错了什么?谢谢你的安慰。

PS : var csvfile = d3.csv.parse(VariableWithcsvFileInside);工作...

很难说发生了什么,因为您没有包含从 url 加载和解析数据的代码,但这就是它应该的工作方式:

// ssv is "Semicolon Separated Values" parser
var ssv = d3.dsv(";", "text/plain");
// Load and (later, asynchronously) parse the data
ssv(url, function(data) {
  console.log(data); // should log an array of parsed values
});

如果数据已经加载并且只需要解析,那么第二行变为:

var data = ssv.parse(stringOfDataThatWasAlreadyLoaded);
console.log(data); // should log an array of parsed values