2015-09-07 120 views
0

我想用條件格式標籤系列數據,但它不適用於我。請幫我解決這個問題。我已經將我的代碼粘貼到基於閾值的基礎數據系列上,但我無法這樣做。如果我評論if條件,那麼標籤顯示整個系列。Highcharts條件數據標籤

$(function() { 
$('#container').highcharts({ 

    xAxis: { 
     categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
    }, 

    plotOptions: { 
     series: { 
      dataLabels: { 
       enabled: true, 
       if(this.y: >130){ 
        format: '{y} mm' 
       } 
      } 
     } 
    }, 

    series: [{ 
     data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] 
    }] 
}); 
}); 

回答

2

使用formatter option使用包含你的邏輯,並返回你想要的格式回調。請參閱文檔鏈接瞭解回調中可用的數據。

更換format與此formatter

formatter: function() { 
    return this.y > 130 ? this.y + ' mm' : null; 
} 

這裏有一個JSFiddle example

+0

非常感謝您的幫助 – Bilal

+0

還有一個問題:如果我想進行其他格式設置,如工具提示或粗體等,那麼我必須爲每種樣式放置多個條件格式化函數?有一種方法可以一次性返回多個樣式選項和一個格式化函數。 – Bilal