javascript 使用 Flot JQuery 库更改现有图上的轴最小值/最大值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17735447/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:25:40  来源:igfitidea点击:

Changing axis min/max on an existing plot using Flot JQuery Library

javascriptjquerygraphzoomflot

提问by jfaghihnassiri

I've created a series of plots using the flot library, which are all displayed on a single page. Is there a way to update the X axis min and max options (options.xaxis.min, options.axis.max) values WITHOUT re-plotting the plots ($.plot('placeholder',data,options))?

我使用 flot 库创建了一系列图,它们都显示在一个页面上。有没有办法更新 X 轴的最小值和最大值选项(options.xaxis.min,options.axis.max)而不重新绘制图($.plot('placeholder',data,options))?

I found this solution: http://osdir.com/ml/flot-graphs/2012-02/msg00064.htmlWhich suggests that the following line would do it, but it does not work for me - the plots visible min and max are not modified based on this call.

我找到了这个解决方案:http: //osdir.com/ml/flot-graphs/2012-02/msg00064.html这表明以下行可以做到,但它对我不起作用 - 图中可见的最小值和最大值不会基于此调用进行修改。

monitorGraph.getOptions().xaxis[0].max = xaxis.max;

Any tips on updating the graphs xaxis max and min values would be greatly appreciated!

任何有关更新图表 xaxis 最大值和最小值的提示将不胜感激!

EDIT: Solution Below

编辑:下面的解决方案

The following code will take an existing plot, update the range that is visible, and redraw it in a very light and efficient way.

以下代码将采用现有绘图,更新可见范围,并以一种非常轻松高效的方式重新绘制它。

            plot.getOptions().xaxis[0].min = time.start;
            plot.getOptions().xaxis[0].max = time.end;
            plot.setupGrid();
            plot.draw();

采纳答案by matty-d

After you set the value of the yaxis max height, try

设置 yaxis 最大高度的值后,请尝试

yourPlot.setupGrid();

Not sure if it'll be as smooth as you want but I think it does the trick.

不确定它是否会像你想要的那样顺利,但我认为它可以解决问题。

回答by Baumi

You can also dynamically modify MIN/MAX parameters in axis options:

您还可以在轴选项中动态修改 MIN/MAX 参数:

plot.getAxes().xaxis.options.min = 0;
plot.getAxes().xaxis.options.max = 999; 

plot.setupGrid();
plot.draw();