简体   繁体   English

使用人力车的时间序列图。 输入数据格式

[英]Chart with time series using Rickshaw. format of input data

I am willing to draw a chart with Rickshaw ( javascript library working with D3 ). 我愿意使用Rickshaw (与D3一起使用的javascript库)绘制图表。 My data look as follows: 我的数据如下:

var data = [{x : '10:16:00', y : 35.75}, {x : '10:17:00', y : 35.78},  {x : '10:18:00', y : 31.04}];

But that just doesn't work with a simple code such as: 但这不适用于简单的代码,例如:

var graph = new Rickshaw.Graph( {
    element: document.querySelector("#chart"), 
    width: 200, 
    height: 200, 
    series: [{
        color: 'steelblue',
        data: data
    }]
});

graph.render();

An error message reads data is indefined. 错误消息读取数据未定义。 It seems to me the problem is due to my x s above being strings and not eg increasing integers. 在我看来,问题出在我的x s是字符串而不是例如增加整数。

Do I have to cast the x s to some javascript time format? 我是否必须将x为某些javascript时间格式? How do I do that? 我怎么做?

You will need to define the x-axis as a timeline: 您需要将x-axis定义为时间轴:

var xAxis = new Rickshaw.Graph.Axis.Time({
    graph: graph,
});
xAxis.render();

Then you give your x axis data as (for the first one): 然后将x轴数据指定为(第一个):

new Date(2014, 11, 4 , 10, 16, 0, 0).getTime()

or using some other Date constructor. 或使用其他一些Date构造函数。

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

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