Highchart:一次只显示一个系列

3

你能在 jsfiddle 上分享代码吗? - Mr.Cocococo
显然管理员将此作为解决方案发布在http://jsfiddle.net/tK38J/8/,但这并不起作用。 - yoshi
2
请查看此链接:http://jsfiddle.net/ctjM7/ - Mr.Cocococo
它可以工作。非常感谢!另一件我想不明白的事情是,我想禁用不显示系列的选项... - yoshi
2个回答

7
问题在于使用了过时的Highcharts链接和旧版本的jQuery。要禁用隐藏系列的可能性,请使用legendItemClick。请参见:http://jsfiddle.net/tK38J/65/
plotOptions: {
  series: {
    events: {
      show: function () {
        var chart = this.chart,
            series = chart.series,
            i = series.length,
            otherSeries;

        while (i--) {
          otherSeries = series[i];
          if (otherSeries != this && otherSeries.visible) {
            otherSeries.hide();
          }
        }
      },
      legendItemClick: function () {
        if (this.visible) {
          return false;
        }
      }
    }
  }
},

很棒的解决方案!谢谢@Pawel Fus - kluu

0
一种更紧凑的方法。它还可以处理多个系列,这些系列组合在一个图例项中。
                    events: {
                    legendItemClick: function () {
                        if (this.visible) {
                            return false;
                        }else{
                            let series = this.chart.series,
                                i = series.length,
                                otherSeries;
                            while(i--) {
                                otherSeries = series[i]
                                if (otherSeries != this && otherSeries.visible) {
                                    otherSeries.hide();
                                }
                            }
                        }
                    }
                },

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接