如何保存(preserve)海军报图上更新的缩放状态与AJAX [英] How to save (preserve) the zoom state of flot graphs on Update with AJAX

查看:86
本文介绍了如何保存(preserve)海军报图上更新的缩放状态与AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,民意调查数据库进行数据的每一分钟。当新的数据被取出,我使用AJAX更新图表。但是,每当我更新的图形(重新绘制它添加了绘制数据的新值)变焦的当前状态将丢失。更新图形之前,我想preserve最新的变焦位置。更新图之后,我希望图形放大到其保存的位置。这很重要,因为重新缩放每一分钟都是那么刺激。这可能吗?

I have a simple application which polls database for data every minute. When new data is fetched, I am updating the graph using ajax. However, whenever I update the graph (re-plot it with new values added to plot data) the current state of zoom is lost. Before updating the graph, I want to preserve the latest zoom position. After updating the graph, I want to zoom the graph to its saved position. This is important because re-zooming every minute is irritating. Is this possible?

推荐答案

在您重新积得到当前的变焦之前获得新的数据和 它添加到更新的选项。

Here is the answer by Joshua Varner 1

When you get your new data before you re plot get the current zoom and add it to the options on update.

// Get the current zoom
var zoom = plot.getAxes();

// Add the zoom to standard options
var zoomed = {};
$.extend(zoomed,options);
zoomed.xaxis.min = zoom.xaxis.min;
zoomed.xaxis.max = zoom.xaxis.max;
zoomed.yaxis.min = zoom.yaxis.min;
zoomed.yaxis.max = zoom.yaxis.max;

// draw/save the plot
plot = $.plot($("#graph"), d, zoomed);

这篇关于如何保存(preserve)海军报图上更新的缩放状态与AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆