Highcharts:工具提示点格式为十进制到百分比

Highcharts : Tooltip pointFormat decimal to percent

本文关键字:十进制 百分比 格式 工具提示 Highcharts      更新时间:2023-09-26

我必须使用pointFormat属性来格式化工具提示。问题是,我无法找出一种方法来使用{point.y}(0.0324123),并使其格式为百分比(3.24)。

正如我上面所说的,我必须在tooltip.pointFormat中这样做。我当前的代码看起来像这样

$highcharts[$key]['tooltip'] = [
    'pointFormat' => '<p style="margin:0;"><span style="color:{series.color};">{series.name}</span>: <b>{point.y:,.2f}%</b></p>'
];

是否有办法做{point.y:,.2f} * 100内html/HighCharts语法?

这是DEMO您必须像这样使用tooltip.formatter选项(将返回截断到小数点后两位的值):

tooltip: {
                //valueSuffix: '°C',
                enabled: true,
                formatter:function(){
                  return '<span style="color:'+this.series.color+'">'+this.series.name+'</span>: <b>'+Highcharts.numberFormat((this.y*100),2,'.')+'%</b>';
                }
            },

在进一步研究之后,没有办法使用'pointFormat'和multiple(转换为百分比)。

解决方案:不要使用0.035,使用3.50。如果你这样做,Highcharts将正确格式化轴。

编辑:下面有一种方法来做到这一点使用Formatter,如果这是你想做的。