简体   繁体   English

Highcharts 限制为 1 yaxis

[英]Highcharts limit to 1 yaxis

I have found a need to make sure Highcharts is only using 1 yaxis at a time, Basically I typically have about 5-10 series but many do not have the same yaxis measurement.我发现需要确保 Highcharts 一次只使用 1 个 yaxis,基本上我通常有大约 5-10 个系列,但许多没有相同的 yaxis 测量值。

For instance with air pollution PM2.5 is measured by ug/m3 and most others are by ppm, but there is also ppb.例如,空气污染 PM2.5 以 ug/m3 衡量,其他大多数以 ppm 衡量,但也有 ppb。

I want to by default show only ppb series, but if you select a series (from the highcharts legend) that uses for instance ug/m3 then all ppb series will be hidden.我想默认只显示 ppb 系列,但如果您选择一个系列(来自 highcharts 图例),例如使用 ug/m3,那么所有 ppb 系列都将被隐藏。

I am having some difficulty defining it so looking through the docs I just can't seem to find any connection to my issue to find a solution, and I really want to avoid trying to force Highcharts to do it when it seems like something that would most likely be supported in some fashion.我在定义它时遇到了一些困难,所以查看文档我似乎无法找到与我的问题的任何联系以找到解决方案,而且我真的想避免在它看起来像某些事情时试图强迫 Highcharts 这样做很可能以某种方式得到支持。

What I am mainly looking for is how this might be termed by highcharts that might direct me to the correct portion of the docs, or if not supported by highcharts what I might be able to do to achieve this without over complicating the setup (click events on the legend items, ect).我主要寻找的是 highcharts 可能如何将其称为文档的正确部分,或者如果 highcharts 不支持,我可能能够在不使设置过于复杂的情况下实现这一目标(点击事件在图例项目上,等等)。

You can achieve this by using series.events.legendItemClick and hide all other series when enabling one.您可以通过使用series.events.legendItemClick来实现这一点,并在启用一个系列时隐藏所有其他系列。 Useful option is also yAxis.showEmpty which will hide all yAxis elements if extremes are not set .有用的选项也是yAxis.showEmpty ,如果未设置极端,它将隐藏所有 yAxis 元素。

Demo: http://jsfiddle.net/BlackLabel/aqh5htqt/演示: http : //jsfiddle.net/BlackLabel/aqh5htqt/

Highcharts.chart('container', {
  yAxis: [{
    showEmpty: false
  }, {
    showEmpty: false
  }, {
    showEmpty: false
  }],
  plotOptions: {
    series: {
      events: {
        legendItemClick: function() {
          if (!this.visible) {
            // Hide all others
            Highcharts.each(this.chart.series, function(series) {
              series.hide();
            });
          } else {
            // Prevent hiding the only visible series
            return false;
          }
        }
      }
    }
  },
  series: [{
    data: [1, 2, 3]
  }, {
    data: [100, 400, 5000],
    visible: false,
    yAxis: 1
  }, {
    data: [5, 10, 15],
    visible: false,
    yAxis: 2
  }]
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM