首页 文章

Highcharts不正确的相关计算

提问于
浏览
0

我的Highcharts饼图错误地计算了一个百分比,我不知道如何/为什么 .

这些是我传递给它的 Value (花费与预算):

budget: 34319326.40 spent: 10000000.00

正确的百分比应该是: 29.14% ,即使我的图表显示 22.56% 已用完 .

在此处查看截图:
enter image description here

如您所见,我的系统计算的百分比是正确的,但由Highcharts计算的百分比较低且不正确 . 下面是我如何传递饼图的系列数据:

series: [{
   name: 'Brands',
   colorByPoint: true,
   data: [{
       name: 'Budget',
       color: '#1e80c1',
       y: parseFloat( budget )
   }, {
      name: 'Spend',
      color: '#fdc942',
      y: parseFloat( spent )
  }]
}]

我怀疑可能我的parseFloat正在影响准确性,但如果我在firebug控制台上进行计算,我会得到正确的结果:

enter image description here

有谁知道可能导致这个问题的原因是什么?提前致谢

1 回答

  • 2

    它根据总 Value 计算

    console.log((10000000.00/(34319326.40+10000000.00)*100).toFixed(2))
    console.log((34319326.40/(34319326.40+10000000.00)*100).toFixed(2))
    

相关问题