更新海军报的数据和轴海军、数据

2023-09-10 22:17:15 作者:老爸老爸我们去哪里呀~

我创建了一个高度互动的图表。所有的相互作用已经实现,而无需重新启动海军报对象。重新启动海军报对象,使互动打破,我也希望有尽可能有效地做到了这一点。

I have created a highly interactive graph. all of the interactions have been achieved without re-initiating the flot object. re-initiating the flot object causes the interactions to break, i would have liked to have done this as efficiently as possible.

的交互我图的支持主要有:

the interactions my graph supports are:

在个别系列变化的可见性 在多个Y轴和它们之间的切换 在放大图(带复位) 单击并拖动平移

最后两个特点我要补充的:

the final two features i have to add are:

在加/减单个系列 在更新各个系列

两者都需要Ajax请求,图表必须支持1000的数据点,这样的效率是关键(我将不得不减少数据点在某一点)。

both of which require ajax requests, the graph must support 1000's of datapoints so efficiency is key (i will have to reduce the datapoints at some point).

正如我提到我已经成功地做​​到了这一切至今没有多次调用$ .plot,我已经使用插件内置的功能,并从getOptions设置一些选项()方法。而不是使用$ .plot我所说的plot.draw()方法来更新图表。但是,我在努力寻找反正推到的数据不涉及调用全功能所提供的方法试(除了这样做使得它更难跟踪变量我改变的选项。)

as i mentioned i have managed to do all of this so far without multiple calls to $.plot, i have used plugins in-built functions and setting some options from the getOptions() method. instead of using $.plot i call the plot.draw() method to update the chart. But, i am struggling to find anyway to push data into the provided methods that don't involve calling the entire function again (besides doing so makes it harder to keep track of the variables i am changing in options.)

我的问题是有没有人有更新的体验,而不是取代,海军报轴和数据使用Ajax请求,你如何能够取得有效的结果?

My question is has anyone had experience with updating, not replacing, flot axes and data using ajax requests and how were you able to achieve efficient results?

推荐答案

你缺少的方法是的 setupGrid 。这将重新创建轴系,而无需重新INITING的情节。

The method you are missing is the setupGrid. This will recreate the axises without re-initing the plot.

在一般我的工作流程modfiying现有的情节是这样的:

In general my workflow for modfiying an existing plot is something like this:

var series = plot.getData(); // reference to your series
series[0].data = someNewArray;
series[0].color = 'blue'; // modify existing series
series.push({data: [[0, 5], [1, 1], [2, 7]], color: 'green'}); // add a new one
plot.setData(series); // you need to set the data so that flot will re-process any newly added series
var opts = plot.getOptions() // get a reference to the options
opts.xaxes[0].min = -1; // adjust an axis min, use the xaxes property NOT the xaxis
// there is no need to "setOptions"...
plot.setupGrid() // if you need to redraw the axis/grid
plot.draw()