2013-03-07 157 views
2

,我們如何根據其狀態更改zIndex或者從點擊事件?使用Highchart更改HighChart中的zIndex

我想:

​​

有:this.setState(this.state === 'select' ? '' : 'select');點擊事件,但它不工作。

+0

在HighCharts源代碼展望(和在這裏的文檔:http://api.highcharts.com/highcharts#plotOptions.series.states.hover)它似乎是允許爲系列更改的唯一屬性是lineWidth,但似乎沒有任何其他屬性的內置功能。如果你想要一個「黑客」的幫助,我可能會弄清楚一些事情。 – MatthewKremer 2013-03-07 14:40:45

+0

如果您不介意花時間,我想知道您的解決方案。 thx – Guian 2013-03-07 14:50:59

回答

2

好吧,它絕對不是很漂亮,但我找不到一個方法來真正設置zIndex,所以我必須做一些操作來僞造它,並按照特定的順序將每個系列放到前面。這裏的片段包括:

Highcharts.Series.prototype.setState = (function (func) { 
     return function() { 
      if (arguments.length>0){ 
       if (arguments[0] !== ''){ 
        if (typeof this.options.states[arguments[0]]['zIndex'] !== 'undefined'){ 
         this.options.oldZIndex = this.group.zIndex; 
         this.group.zIndex = this.options.states[arguments[0]]['zIndex']; 
        } 
       }else{ 
        if (typeof this.options['oldZIndex'] !== "undefined"){ 
         this.group.zIndex = this.options['oldZIndex']; 
        } 
       } 
       var order = [], i = 0; 
       $.each(this.chart.series, function(){ 
        order.push({id:i,zIndex:this.group.zIndex,me:this}); 
        i++; 
       }); 
       order.sort(function(a,b){return (a.zIndex>b.zIndex) ? 1 : -1;}); 
       $.each(order, function(){ 
        this.me.group.toFront(); 
       }); 
       func.apply(this, arguments); 
      } 
     }; 
    } (Highcharts.Series.prototype.setState)); 

而這裏的示範的jsfiddle:

http://jsfiddle.net/G9d9H/9/

讓我知道,如果這就是你需要的。

+0

另外,如果你打算將這個結合我對你的其他問題的回答,你應該把這個黑客放在你的代碼中的另一個之前。 – MatthewKremer 2013-03-07 16:00:21

+0

我也會試試,謝謝。 – Guian 2013-03-09 08:01:18

0

我認爲更好的解決方案是設置點擊series.group.toFront()方法(我更喜歡把它用在鼠標懸停)

plotOptions: { 
     series: { 
      events: { 
       click: function() { 
        this.group.toFront();//bring series to front when hovered over 
       } 
      } 
     } 
    }