【问题标题】:Highchart: Only show one series at a timeHighcharts:一次只显示一个系列
【发布时间】:2018-09-14 15:25:36
【问题描述】:

我只想一次显示一个系列。 我还想禁用不显示任何系列的选项。

我发现了这个:http://forum.highcharts.com/viewtopic.php?f=9&t=6399 但答案不起作用。

【问题讨论】:

  • 可以分享jsfiddle中的代码吗?
  • 显然管理员将此作为解决方案发布jsfiddle.net/tK38J/8,但这不起作用。
  • jsfiddle.net/ctjM7 看看这个
  • 它有效。非常感谢!我想不通的另一件事是我想禁用根本不显示系列的选项...

标签: javascript highcharts


【解决方案1】:

问题在于使用过时的 Highcharts url 和旧版本的 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
【解决方案2】:

一种更紧凑的方式。它也适用于组合在一个图例项目中的多个系列。

                    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();
                                }
                            }
                        }
                    }
                },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多