最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Highcharts: Get visibility of series after legendItemClick - Stack Overflow

programmeradmin3浏览0评论

I have a chart with multiple series which I would like to modify the options of, if two of the series have been disabled by clicking on the legend.

The following won't work as visible has the value of the state before it was clicked. Is there another way to do what I am trying to acplish below?

plotOptions: {
    series: {
        events: {
            legendItemClick: function(event) {
                if(this.yAxis.series[0].visible && this.yAxis.series[1].visible) {
                    // do some action
                }
            }
        }
    }
},

I have a chart with multiple series which I would like to modify the options of, if two of the series have been disabled by clicking on the legend.

The following won't work as visible has the value of the state before it was clicked. Is there another way to do what I am trying to acplish below?

plotOptions: {
    series: {
        events: {
            legendItemClick: function(event) {
                if(this.yAxis.series[0].visible && this.yAxis.series[1].visible) {
                    // do some action
                }
            }
        }
    }
},
Share Improve this question asked Dec 31, 2013 at 7:07 dan-klassondan-klasson 14.2k14 gold badges67 silver badges105 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can get this behavior a little modyfing your function:

plotOptions: {
  series: {
    events: {
      legendItemClick: function(event) {
          var series = this.yAxis.series,
              seriesLen = series.length,
              visible = this.visible ? 1 : -1; 
              // +1 when visible series, because it will be changed after that callback

          for(var i = 0; i < seriesLen; i++) {
            if(!series[i].visible) {
              visible++;
            }
          }
          if(visible >= 2){
            //do some action
          }
      }
    }
  }
},
发布评论

评论列表(0)

  1. 暂无评论