我有阵列:
var array = [];
var object1 = {};
object1.x = 1458083620;
object1.y = 5;
array.push(object1);
var object2 = {};
object2.x = 1458083690;
object2.y = 4;
array.push(object2);
我想要显示这个数组:
var graph = new Rickshaw.Graph({
element: document.querySelector("#chart"),
renderer: 'scatterplot',
width: 500,
height: 300,
series: [{
data: array,
color: 'steelblue',
name: 'count'
}]
});
var y_axis = new Rickshaw.Graph.Axis.Y({
graph: graph,
orientation: 'left',
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
element: document.getElementById('y_axis')
});
graph.render();
var hoverDetail = new Rickshaw.Graph.HoverDetail( {
graph: graph
} );
但是在屏幕上我看到,同一行中的2个元素(object1
和object2
)。
如何按小时/分钟/秒分组元素?
注意:HTML代码
<div id="chart_container">
<div id="y_axis"></div>
<div id="chart"></div>
</div>
答案 0 :(得分:1)
将x和y属性分配给对象的方式可能是问题所在。
您可以尝试分配对象属性,如下例所示。
使用Javascript:
//array to hold objects
var array = [];
//object1 with its properties
var object1 = {
"x":1458083620,
"y":5
};
//add object1 to the array
array.push(object1);
//object2 with its properties
var object2 = {
"x":1458083690,
"y":4
};
//add object2 to the array
array.push(object2);