2015-07-03 55 views
6

我正在尋找隱藏highcharts中的第一個yAxis標籤。我無法找到如何做這個選項。這個問題緊密地迴避了這個問題:Hide first yaxis label。然而,我正在尋找的解決方案是高層圖。隱藏Highcharts中的第一個yAxis標籤

yaxis hide

從上面的圖片,我只是想爲-10被隱藏。我需要添加什麼options來完成這個?

下面添加的代碼只是一個通用函數,我創建了一個參數,我已經命名了選項(一個對象),我已經設置了選項列表(如標題,字幕,系列)。 ..)。

var hc_bubble = function(options){ 
    $(options.target).highcharts({ 
     chart: { 
     type: 'bubble', 
     zoomType: 'xy' 
     }, 
     title: { 
     text: options.title || 'unknown' 
     }, 
     subtitle: { 
     text: options.subtitle || '' 
     }, 
     xAxis: { 
     type: options.date || 'datetime', 
     labels: { 
        formatter: function() { 
         return Highcharts.dateFormat("%b %Y", this.value) 
        } 
       }, 
     title: { 
      enabled: true, 
      text: options.xTitle || 'unknown' 
     }, 
     startOnTick: true, 
     endOnTick: true, 
     showLastLabel: true 
     }, 
     yAxis: { 
     title: { 
      text: options.yTitle || 'unknown' 
     } 
     }, 
     tooltip:{ 
     headerFormat: '<b>{series.name}</b><br>', 
     pointFormat: '{point.y} ' + options.yType || 'Connections' 
     }, 
     series: options.series 
    }); 
} 
+2

[yAxis.showFirstLabel](http://api.highcharts.com/highcharts#yAxis.showFirstLabel)設置爲false。 –

回答

2

我不會在第一次發佈這個問題,因爲我只是找到了答案(在docs了一會兒後,搜索),但我想這可以幫助別人。

只需確保添加在您的標籤formatter callback對象:

yAxis: { 
    labels:{ 
     formatter: function(){ 
     if(this.value >= 0){ 
      return this.value; 
     } 
     } 
    } 
    } 

http://api.highcharts.com/highcharts#yAxis.labels.formatter

3

當你的解決方案的工作,有一個稍微更通用的解決方案,如果你的目的始終是防止你可能會喜歡yAxis在左下角有一個標籤:

yAxis: { 
    labels: { 
     formatter: function() { 
      if (this.isFirst) { return ''; } 
      return this.value; 
     } 
    } 
}, 

利用isFirst屬性即高圖表有this可以防止您對「幻數」的依賴(類似地,如果您想嘗試一下,則有isLast值 - 儘管我沒有看到它的用處)。