jQuery 在 Javascript 中刷新/重新加载浮点数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6024474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh/Reload Flot In Javascript
提问by dhulihan
Hey Guys, does anyone know how to reload a flot graph in javascript? For instance, I want to redraw the graph every time an input value is changed. I tried experimenting with a few methods found in the flot API, such as draw()and setupGrid()without any luck.
嘿伙计们,有谁知道如何在 javascript 中重新加载浮动图?例如,我想在每次更改输入值时重新绘制图形。我尝试尝试了在Flot API 中找到的一些方法,例如draw()和setupGrid() ,但没有任何运气。
Here's some example code:
下面是一些示例代码:
$("#some_input_box").change(function(){
plot.draw(); // redraw graph
});
回答by Ryley
You are on the right track with draw
and setupGrid
, here's what you need to do:
您在正确的轨道上使用draw
和setupGrid
,这是您需要做的:
var plot = $.plot($('#placeholder'),data,options);
//time passes, you now want to replot
var newData = [[0,2],[1,3],[2,5]];
plot.setData(newData);
plot.setupGrid(); //only necessary if your new data will change the axes or grid
plot.draw();
Alternatively, it's not too much worse to just re-call $.plot
. The above way is more efficient, but...
或者,只是重新调用$.plot
. 上面的方法效率更高,但是...