[英]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.