flot:如何计算y轴数 [英] flot: How to count the number of y-axes

查看:64
本文介绍了flot:如何计算y轴数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我为线图声明了一些y轴(温度,湿度等).但我可以显示\隐藏一些系列.

In my project I declare some y-axes (temperature, humidity, etc) for line-charts. but I can show\hide some of the series.

我只想在屏幕上有一些y轴时突出显示工具提示项的y轴

I want to highlight the y-axes of tooltip item only if there are some y-axes on the screen

我认为我可以使用

  var isMultyYaxes = ( $(".flot-y-axis").length > 1 );
  if (isMultyYaxes) {
    $(".y" + item.series.yaxis.n + "Axis").addClass("myActiveAxis"); 
  }

但是似乎$(.flot-y-axis")中有重复的y轴.

but it seems there are duplicate y-axes in $(".flot-y-axis").

我应该使用-

  var isMultyYaxes = ( $(".flot-y-axis").length > 2 );

还有其他方法可以确定当前使用了多少个y轴吗?

Is there another way to determine how many y-axes are currently used?

推荐答案

如果您已经存储了对绘图对象的引用(使用var plot = $.plot(...);),则可以获得如下所示的选项和轴:

If you have stored a reference to your plot-object (with var plot = $.plot(...);) then you can get the options and the axes like this:

var yAxesCountAll = plot.getOptions().yaxes.length;

然后您可以检查轴是否显示如下:

Then you can check if the axes are shown like this:

var yAxesCountVisible = 0;
for (var i = 1; i <= yAxescountAll; i++) {
    if (plot.getAxes()['y' + (i == 1 ? '' : i.toString()) + 'axis'].show) {
        yAxesCountvisible++;
    }
}

这篇关于flot:如何计算y轴数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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