2014-11-13 60 views
0

我無法解釋此行爲:
有時,我的圖表顯示的軸的第一個或最後一個標籤有很多小數。Highcharts:使用軸的問題標籤

enter image description here enter image description here

在我的圖形選項,這裏是y軸什麼樣子:

yAxis : [{ 
    alternateGridColor: "white", 
    gridLineColor : "#E3E3E3", 
    lineWidth: 2, 
    tickLength : 5, 
    lineColor : '#A5A5A5', 
    tickWidth : 2, 
    tickLength : 5, 
    tickColor : '#A5A5A5', 
    labels : { 
     style : { 
      fontWeight : 'bold', 
      fontSize: '10px' 
     }, 
     x : -labelMargin 
    }, 
    tickPixelInterval: 20 
}, 
//more axis 
] 

如何解決呢?任何幫助讚賞。

回答

1

你沒有提到你的標籤的價值,所以它使用天真的價值,可能是一個部門生成的浮動數字。

我建議你來處理您的標籤手動是這樣的:

labels: { 
     formatter: function() { 
      return Math.floor(this.value) 
     } 
    } 

正如你可以看到我使用floor()函數刪除小數。

+1

我已經添加了'format:'{value:.2f}''並且如預期的那樣,它可以防止這種奇怪的行爲再次出現。但是當軸顯示「更大」的值(我的意思是1,2,3)時,我不希望軸顯示小數。任何提示? – zbMax

+0

我認爲你可以再次做數學運算。例如,根據我的答案,它應該是這樣的: 'return(this.value - Math.floor(this.value))'將小數分開。 – muradin

+0

@zbMax使用[標籤格式化程序](http://api.highcharts.com/highcharts#yAxis.labels.formatter)和[Highcharts.numberFormat](http://api.highcharts.com/highcharts#Highcharts.numberFormat )支持任何檢查值的條件。 –