Apexchart 甜甜圈显示错误的总数字
Apexchart donut display wrong total figure
Donut Chart Image
总和应为 31,392.82,但圆环图中显示的总和为 31392.8299999999996。
- 我做错了什么吗?还是 apexchart 错误?
- 如何格式化总计显示千位分隔符 & 到小数点后 2 位。
下面的标签和系列代码:
let colorPalette = ['#00D8B6', '#008FFB', '#FEB019', '#FF4560', '#775DD0'];
let usage_by_category_labels = [ "Entertainment", "Food", "Household Items/Supplies", "Insurance", "Medical/Healthcare", "Miscellaneous", "onCloud","Personal", "Transport","Utilities"];
let usage_by_category_series = [78.80, 15381.25, 307.90, 1170.00, 663.90, 4938.92, 2506.12, 2522.85, 3152.11, 670.97];
调用floating-point错误:https://floating-point-gui.de/
四舍五入 formatter
https://apexcharts.com/docs/options/plotoptions/pie/#totalFormatter
formatter: function (w) {
let result = w.globals.seriesTotals.reduce((a, b) => a + b, 0)
return Math.round(result * 100) / 100 // * 100 for 2 decimal numbers
}
Donut Chart Image
总和应为 31,392.82,但圆环图中显示的总和为 31392.8299999999996。
- 我做错了什么吗?还是 apexchart 错误?
- 如何格式化总计显示千位分隔符 & 到小数点后 2 位。
下面的标签和系列代码:
let colorPalette = ['#00D8B6', '#008FFB', '#FEB019', '#FF4560', '#775DD0'];
let usage_by_category_labels = [ "Entertainment", "Food", "Household Items/Supplies", "Insurance", "Medical/Healthcare", "Miscellaneous", "onCloud","Personal", "Transport","Utilities"];
let usage_by_category_series = [78.80, 15381.25, 307.90, 1170.00, 663.90, 4938.92, 2506.12, 2522.85, 3152.11, 670.97];
调用floating-point错误:https://floating-point-gui.de/
四舍五入 formatter
https://apexcharts.com/docs/options/plotoptions/pie/#totalFormatter
formatter: function (w) {
let result = w.globals.seriesTotals.reduce((a, b) => a + b, 0)
return Math.round(result * 100) / 100 // * 100 for 2 decimal numbers
}