d3.js TSV到Javascript变量 [英] d3.js TSV to Javascript variable

查看:192
本文介绍了d3.js TSV到Javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用d3.js库的图形。
3d.js tsv解析器创建如下的d变量:

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

代码:

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

现在你使用'd.day'和'd.Value'构建你的图 - scaterplots,linegraph等...

and now you use 'd.day' and 'd.Value' to build your graph - scaterplots, linegraph, etc...

我不会使用tsv文件,而是一个javascript变量。是最正确的(如果可能的话)javascript变量表示,以便在3d.js中使用这个d.day和d.Value并按照惯例像'svg.data(data)'一样解析它?

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)'?

推荐答案

如果你不是从文件读取,你仍然可以使用JSON格式(这是你在说什么)。json变量的格式如下:

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"
}

您可以在这里找到有关JSON格式的更多信息: http://www.json.org/

You can find out more information about the JSON format here: http://www.json.org/

这篇关于d3.js TSV到Javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆