一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Highcharts报表插件多余小数位BUG的修复

时间:2012-11-25 编辑:简简单单 来源:一聚教程网

但是实际应用中一旦数据里质数多了起来,Highcharts 的报表就会出现小数位处理不当的问题(尽管我们已经对数据四舍五入取点了),具体如图。

 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 处理后的效果图,

Highcharts报表插件
 
美中不足的一点是,这样处理之后的项目总和可能不为100%了。无奈

热门栏目