如何解析获得d3.js中的数据 [英] How to parse to get the data in d3.js

查看:261
本文介绍了如何解析获得d3.js中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多困惑的解析年,月,日,小时。如何显示给定的数据。

  var parseDate = d3.time.format(%d%b)。parse; 
var data = [{key:[2000,0,1,0],value:1000},{key:[2000,1,1,1]},value 2000},{key:[2000,2,2,2]},value:3000},{key:[2000,4,4,4]},value:5000}]
i写下面的代码
var data1 = data.map(function(d,i){return {key:parseDate((d.key [1])++ d.key [0 ]),value:+ d.value}});
console.log(data1)


解决方案

时间格式化描述如下:
https://github.com/mbostock/d3/ wiki / Time-Formatting



假设你的键数组是[年,月,日,小时(24小时)],你需要写:

  var parseDate = d3.time.format(%Y.%m。%d。%H)。 
...
var data1 = data.map(function(d,i){
return {key:parseDate(
(d.key [0] +。 + d.key [1] +。d.key [2])+。+ d.key [3])
,value:+ d.value}
}基于以下链接,我怀疑a)您在不同的用户名下发布您的问题和b)你不接受答案。请参阅



如何从d3.js中给定的对象数组获取数据



我无法显示x轴年份和月份使用d3.js


I have lot of confused for the parsing year,month,day,hour.How to show for he given data.

 var parseDate =d3.time.format("%d %b").parse;
 var data=[{"key":[2000,0,1,0],"value":1000},{"key":[2000,1,1,1]},"value":2000},{"key":[2000,2,2,2]},"value":3000},{"key":[2000,4,4,4]},"value":5000}]
i wrote the code is given below
var data1 = data.map(function (d,i){return {key:parseDate((d.key[1])+" "+d.key[0]),value:+d.value}});
console.log(data1)

解决方案

Time formatting is described here: https://github.com/mbostock/d3/wiki/Time-Formatting

Assuming your key array is [year,month,day,hour(24hours)] you need to write:

var parseDate = d3.time.format("%Y.%m.%d.%H").parse;
...
var data1 = data.map(function (d,i){
return {key:parseDate(
(d.key[0]+"."+d.key[1]+"."d.key[2])+"."+d.key[3])
,value:+d.value}
});

Based on the links below, I suspect a) you are posting your questions under different usernames and b) you don't accept answers. See

How to get the data from given array of objects in d3.js

I unable show the x-axis year and month using d3.js

这篇关于如何解析获得d3.js中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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