简体   繁体   English

如何在隐藏系列的同时保持高图表图例的“打开”状态

[英]How to keep the highcharts legend “on” while hiding the series

I added some dummy series in the highcharts, but I want them to be invisible at all times, independent of whether I click their legends. 我在highcharts中添加了一些虚拟系列,但我希望它们始终不可见,与是否单击它们的图例无关。

series.push({
    name: 'dummyPoint',
    fontFamily: 'Arial',
    data: [dummyPointX, dummyPointY],
    visible: false,
    showInLegend: true
})

The problem with the above code is that the legends are displayed greyed out by default, and it will display dummies upon the click of legends. 上面的代码的问题在于,图例默认情况下显示为灰色,并且在单击图例时将显示假人。 How do I prevent it from greying out by default and keep the dummy points invisible at all times? 如何防止默认情况下它变灰并使虚拟点始终不可见?

You can do that with the series.events.legend.itemClick - Api Documentation 您可以使用series.events.legend.itemClick - Api文档

  series: [{
    name: 'Point 1',
    color: '#00FF00',
    data: [1, 2.5, 3, 4, 3.2],
    visible: false,
    showInLegend: true,
    events: {
      legendItemClick: function() {
        return false;
      }
    }
  }

edit : Completly invisible legend Updated Fiddle 编辑 :完全不可见的传说更新小提琴

You can do a little trick to achieve it: create a "phantom" series that has no data and link the hidden series to it. 您可以做一些技巧来实现它:创建一个没有数据的“幻影”系列并将隐藏的系列链接到该系列。 Legend item will be generated for the phantom series and will serve for the hidden series too. 图例项目将为幻影系列生成,也将用于隐藏系列。 Then disable the default action for this item in events.legendItemClick : 然后在events.legendItemClick禁用此项目的默认操作:

  series: [{
    // Phantom series - created just to generate legend item
    name: 'Series 1',
    events: {
      legendItemClick: function(e) {
        e.preventDefault();
      }
    }
  }, {
    data: [3, 0],
    visible: false,
    name: 'Series 1',
    linkedTo: ':previous',
  }, {
    data: [1, 2],
    name: 'Series 2'
  }]

Live demo: http://jsfiddle.net/BlackLabel/dc4L30zv/ 现场演示: http : //jsfiddle.net/BlackLabel/dc4L30zv/

API references: API参考:

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

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