简体   繁体   English

d3.js TSV到Javascript变量

[英]d3.js TSV to Javascript variable

I'm working on a graph with d3.js library. 我正在使用d3.js库进行图形处理。 The 3d.js tsv parser creates the 'd' variable as such: 3d.js tsv解析器按如下方式创建“ d”变量:

TSV: TSV:

day Value
01-01   50
01-02   45
01-03   60

code: 码:

d3.tsv("data.tsv", function(error, data){...}

and now you use 'd.day' and 'd.Value' to build your graph - scaterplots, linegraph, etc... 现在您使用'd.day'和'd.Value'来建立图表-scaterplots,linegraph等...

I won't be using a tsv file but a javascript variable instead. 我不会使用tsv文件,而是使用javascript变量。 Which is the most correct (if possible) javascript variable representation in order to use this d.day and d.Value in 3d.js and parsing it conventionally like 'svg.data(data)'? 为了在3d.js中使用此d.day和d.Value并按常规方式像“ svg.data(data)”一样对其进行解析,哪一种是最正确(如果可能)的javascript变量表示形式?

If you're not reading from a file, you can still use the JSON format (which is what you're talking about). 如果您不是从文件中读取文件,则仍然可以使用JSON格式(这就是您所要的内容)。 The format for a json variable is as follows: json变量的格式如下:

var myVariable = {
"indexA" : "valueA",
"indexB" : "valueB"
}

You can even have an array as the value (even though you didn't ask) and that would look very similar: 您甚至可以将一个数组作为值(即使您没有询问),这看起来非常相似:

var myVariable = {
"indexA" : [ "indexA1": "valueA1", "indexA2": "valueA2", ...],
"indexB" : "valueB"
}

You can find out more information about the JSON format here: http://www.json.org/ 您可以在此处找到有关JSON格式的更多信息: http : //www.json.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM