我正在尝试使用Rickshaw制作基于socket.io的实时图形。我尝试在Rickshaw github的socket.io example上构建,但是当我向图表中添加轴时,每次数据更新都会重新创建它们,而先前的轴仍然存在。例如,经过3次更新后,我会在彼此顶部放置3个y轴,依此类推。我在做什么错?这是我的代码:
Rickshaw.Graph.Socketio.Static = Rickshaw.Class.create( Rickshaw.Graph.Socketio, {
request: function() {
var socket = io.connect(this.dataURL);
thisData = this;
socket.on('rickshaw', function (data) {
console.log("Got some fancy Websocket data: ");
console.log(data);
thisData.success(data);
});
}
} );
var socketioGraph = new Rickshaw.Graph.Socketio.Static( {
element: document.getElementById("chart"),
min: 0,
max: 5,
width: 800,
height: 200,
renderer: 'bar',
dataURL: "http://myhostname",
onData: function(d) { Rickshaw.Series.zeroFill(d); return d },
onComplete: function(transport) {
var graph = transport.graph;
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
element: document.getElementById('y_axis')
});
yAxis.render();
var xAxis = new Rickshaw.Graph.Axis.Time( {graph: graph} );
xAxis.render();
}
} );
谢谢!