Highcharts报表插件多余小数位BUG的修复
Highcharts 官方的DEMO数据很完美很好看。【jQuery报表插件
】
但是实际应用中一旦数据里质数多了起来,Highcharts 的报表就会出现小数位处理不当的问题(尽管我们已经对数据四舍五入取点了),具体如图。
我的解决办法是,查看未压缩的原开发版JS,版本:license Highcharts JS v2.2.4 (2012-05-31)
。
Point.prototype 这个类里的getLabelConfig函数中的percentage字段的值修改为”Math.round(point.percentage,2)“。
第10938行。
完整函数片段为,
/**
* Return the configuration hash needed for the data label and tooltip formatters
*/
getLabelConfig: function () {
var point = this;
return {
x: point.category,
y: point.y,
key: point.name || point.category,
series: point.series,
point: point,
percentage: Math.round(point.percentage,2),
//point.percentage
total: point.total || point.stackTotal
};
},
接着对Highcharts代码净化压缩即可放到生产环境里。
再看看我对这个jquery报表插件
Highcharts
处理后的效果图,
美中不足的一点是,这样处理之后的项目总和可能不为100%了。无奈~
本文永久地址:https://sjolzy.cn/BUG-repair-Highcharts-report-plug-in-the-extra-decimal-places.html
--EOF--