工作中用到highcharts制作图表的时候,遇到了一下这种过于精确的“float”类型的情况,难免引起用户体验不爽;
巧的是之前测试的数据都是比较友好的数据(也是醉), 项目实施时大概变成了这样,绝非本coder本意。
code:
formatter: function() {
//this 为当前的点(扇区)对象,可以通过 console.log(this) 来查看详细信息
return '<span style="font-size:'+15+"px"+'">数量:' + this.y + ',占比' + this.percentage + '%</span>';
}只需要将其中使用到百分数的地方的参数设置为Highcharts.numberFormat(this.percentage, x), x为精确到小数点后位数。
修改后的代码:
formatter: function() {
//this 为当前的点(扇区)对象,可以通过 console.log(this) 来查看详细信息
return '<span style="font-size:'+15+"px"+'">数量:' + this.y + ',占比' +Highcharts.numberFormat(this.percentage, 2)+ '%</span>';
}效果为:
okay。。。。搞定
版权声明:本文为kirinlau原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。