2014-04-19 75 views
0

我使用2個數組並獲取百分比。我想要做的是,如果兩個數組索引都是0,我想將標籤設置爲「無數據」。我知道我需要獲得當前列(點)索引或類似的東西,我試過使用格式化程序來做到這一點。HighCharts設置不同的xAxis標籤

無論如何,我想代碼是這樣的。

xAxis: { 
    categories: trebleNotes, 
     labels: { 
       rotation: -45, 
       align: 'right', 
       style: { 
        fontSize: '13px', 
        fontFamily: 'Verdana, sans-serif' 
       }, 
       formatter: function() { 
       if(array1[currentColumn] == 0 && array2[currentColumn] == 0){ 
         return("NO DATA"); 
         }else{ 
         return(this.value); 
         } 
       }, 
      } 
     }, 

我不知道如何獲取currentColumn索引,並使用它做格式。我希望這是有道理的。

回答

0

如果我的理解正確,難道你只是想要在this.value的類別索引?

 labels: { 
      formatter: function() { 
       var currentColumn = -1; 
       for (var idx = 0; idx < this.axis.categories.length; idx++){ 
        if (this.axis.categories[idx] == this.value){ 
         currentColumn = idx; 
         break; 
        } 
       } 
       console.log(currentColumn); 
       return this.value; 
      } 
     } 
+0

謝謝。這幾乎看起來像它會工作,它允許我得到列索引..但類別是相同的實例(具有相同的值重複)相同,所以我得到的「currentColumn」重複多次。 – james

+0

你有任何現場演示你的圖表嗎? –