如何使用 AJAX 更新时保存(保留)图表的缩放状态
我有一个简单的应用程序,每分钟轮询数据库中的数据。当获取新数据时,我使用 ajax 更新图表。但是,每当我更新图表(使用添加到绘图数据的新值重新绘制它)时,缩放的当前状态就会丢失。在更新图表之前,我想保留最新的缩放位置。更新图表后,我想将图表缩放到其保存的位置。这很重要,因为每分钟重新缩放是令人恼火的。这可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我尝试了 Ozan 的这个答案,但无法获得复制缩放的块来工作,所以我只使用了plot.getOptions()并用它来绘制图表。
像这样:
这样您就可以动态更改您的视图,并且自动更新将在不更改您的视图的情况下进行更新。
I tried this answer from Ozan and I couldn't get the block for copying the zoom to work so I just used plot.getOptions() and used that to draw the graph.
Like this:
This way you can dynamically change your view and the auto-update will update without changing your view.
的回答
以下是 Joshua Varner 1 在重新绘图之前获取新数据获取当前缩放并
将其添加到更新选项中。
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.
您应该获取有关当前轴状态的信息,将其与初始选项合并,然后将它们提供给新绘图。
You should get the information about the state of the current axes, merge it with your initial options and than provide them to the new plot.