gpt4 book ai didi

javascript - Highcharts : yAxis, 值四舍五入到最多两位小数

转载 作者:行者123 更新时间:2023-11-29 21:59:56 24 4
gpt4 key购买 nike

我的图表代码是这样的(从 php 页面获取数据,然后添加一些系列):

$('#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 轴上列出的值超过两位小数。我想将最大小数位数限制为两位。

enter image description here

我想我必须更改此字段 ( format )

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

但我不知道怎么办。

最佳答案

尝试将值写为 {value:.2f},如此处所建议:link

关于javascript - Highcharts : yAxis, 值四舍五入到最多两位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24387494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com