2014-06-24 4 views
2

최대 반올림 값들 내 그래프의 코드는이 (a PHP 페이지로부터 데이터를 받아 다음 약간 시리즈 추가)이다Highcharts : y 축이 소수 둘째 자리

$('#grafico_1').highcharts({ 

chart: { 
    type: 'line', 
    zoomType: 'xy', 
    animation : false, 
    events: { 
    selection: function(event) { 

     if(event.resetSelection){ 

      setTimeout(function(e){ 

       var chart = $('#grafico_1').highcharts(); 
       var extreme = chart.yAxis[0].getExtremes(); 

       var mio_min = parseFloat(proprieta_temperatura_aperto[34]); 
       var mio_max = parseFloat(proprieta_temperatura_aperto[35]); 

       if(extreme.dataMin < mio_min){ 
        mio_min = extreme.dataMin; 
       } 
       if(extreme.dataMax > mio_max){ 
        mio_max = extreme.dataMax; 
       } 

       chart.yAxis[0].setExtremes(mio_min,mio_max); 

       $("#temperatura_min_max_rilevato").html("Min "+extreme.dataMin+"°C - Max "+extreme.dataMax+"°C"); 
       //console.log("zoom - "); 

      }, 10); 
     }else{ 

      setTimeout(function(e){ 
       var chart = $('#grafico_1').highcharts(); 
       var extreme = chart.yAxis[0].getExtremes(); 
       $("#temperatura_min_max_rilevato").html("Min "+extreme.dataMin+"°C - Max "+extreme.dataMax+"°C"); 
       //console.log("zoom + "+JSON.stringify(extreme)); 
      }, 50); 

     } 

    } 
}, 
}, 

credits : { 
    enabled : false 
}, 

title: { 
    text: 'Grafico di Oggi' 
}, 

xAxis: { 
    type: 'datetime', 
    title: { 
     text: false 
    } 
}, 

yAxis: [ 
    { 
     title: { 
      text: false 
     }, 
     labels: { 
     format: '{value}°C', 
    }, 
     //ceiling : parseFloat(proprieta_temperatura_aperto[35]), 
     //floor: parseFloat(proprieta_temperatura_aperto[34]), 
     max : parseFloat(proprieta_temperatura_aperto[35]), 
     min: parseFloat(proprieta_temperatura_aperto[34]), 


    }, 
    { 
     title: { 
      text: false 
     }, 
     min: 0, 
     max : 1, 
     ceiling:1, 
     floor : 0, 
     //tickLength : 1, 
     opposite: true, 
     tickInterval: 1, 
     labels: { 
      formatter: function() { 
       if (this.value == 0 || this.value == 1){ 
        return this.value; 
       }else{ 
        return null; 
       } 
      } 
     } 
    } 
], 


tooltip: { 

    formatter: function() { 

     var s = '<b>Data</b> '+Highcharts.dateFormat('%H:%M:%S', this.x) + '<br><b>Temperatura</b> ' + this.y + '°C<br/>'; 

     $.each(this.points, function(i, point) { 

      if(point.series.name != "Temperatura"){ 
       s += '<b>' + point.series.name +'</b> : '+ point.y + '<br>'; 
      } 

     }); 

     return s; 
    }, 
    shared: true, 
    backgroundColor: '#FCFFC5' 
}, 

plotOptions: { 
    line : { 
     turboThreshold: 0, 
    }, 
    series: { 
     animation: false, 
     marker: { 
      enabled: false 
     } 
    } 
}, 

series: [] 

}); 

문제가 언제 발생 그래프를 한 개 (또는 그 이상) 확대/축소하고 Y 축에서 값은 두 자리 이상으로 나열됩니다. 소수점 이하 최대 자리수를 2로 제한하고 싶습니다.

enter image description here

나는 내가이 분야 (format)

yAxis: [ 
    { 
    labels: { 
     format: '{value}°C', 
     }, 

을 변경할 수 있다고 생각하지만 난 방법을 몰라, 감사합니다! 여기에 제안 된

+0

이 [링크]를합니까 (http://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting) 어쩌면 도움이 될까요? 그래서'{value : .2f}'일까요? –

+0

@Artur Käpp, 네, 감사합니다! – WhiteLine

답변

2

시도는, {value:.2f}로 값을 쓰고 : link

관련 문제