d3.js TSV to Javascript variable

可紊 提交于 2019-12-10 23:52:41

问题


I'm working on a graph with d3.js library. The 3d.js tsv parser creates the 'd' variable as such:

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...

I won't be using a tsv file but a javascript variable instead. 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)'?


回答1:


If you're not reading from a file, you can still use the JSON format (which is what you're talking about). The format for a json variable is as follows:

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/



来源:https://stackoverflow.com/questions/21828101/d3-js-tsv-to-javascript-variable

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