flot: How to count the number of y-axes

你离开我真会死。 提交于 2019-12-24 16:54:30

问题


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

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

I thought I could use

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

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

Should I use -

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

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


回答1:


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++;
    }
}


来源:https://stackoverflow.com/questions/35911706/flot-how-to-count-the-number-of-y-axes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!