如何在 highcharts 图中显示小数值?
How to show decimal values in highcharts graph?
series: [{
name: 'name',
type: 'spline',
data: d1,
tooltip: {
pointFormat: '{series.name}: <b>{point.y:.2f}%</b>'
}
}]
d1=[0.12,-1.58,-0.8]
在图表中显示 0.00,1.00,0.00
您可以使用 formatter
选项来代替 javascript 函数以 return 您需要的格式的值
tooltip: {
formatter: function() {
return getTooltip(this.y);
}
}
将 Highcharts.numberFormat
函数与 formatter
函数结合使用,如 Ahmed Sayed 所述(参见 http://api.highcharts.com/highcharts#Highcharts.numberFormat)。
对于您的特定代码,您可以这样格式化它:
series: [{
name: 'name',
type: 'spline',
data: d1,
tooltip: {
// format the tooltip to return the y-axis value to two decimal places
formatter: function() {
return this.series.name + ': <b>' + Highcharts.numberFormat(this.y,2) + '%</b>';
}
}
}]
希望对您有所帮助。
series: [{
name: 'name',
type: 'spline',
data: d1,
tooltip: {
pointFormat: '{series.name}: <b>{point.y:.2f}%</b>'
}
}]
d1=[0.12,-1.58,-0.8]
在图表中显示 0.00,1.00,0.00
您可以使用 formatter
选项来代替 javascript 函数以 return 您需要的格式的值
tooltip: {
formatter: function() {
return getTooltip(this.y);
}
}
将 Highcharts.numberFormat
函数与 formatter
函数结合使用,如 Ahmed Sayed 所述(参见 http://api.highcharts.com/highcharts#Highcharts.numberFormat)。
对于您的特定代码,您可以这样格式化它:
series: [{
name: 'name',
type: 'spline',
data: d1,
tooltip: {
// format the tooltip to return the y-axis value to two decimal places
formatter: function() {
return this.series.name + ': <b>' + Highcharts.numberFormat(this.y,2) + '%</b>';
}
}
}]
希望对您有所帮助。