From a7ad77fd97d19ba318d9998c988bbc5ed9790666 Mon Sep 17 00:00:00 2001 From: "Mitsuki.Fukunaga" Date: Thu, 20 Jun 2019 12:11:49 +1000 Subject: [PATCH 1/2] fix: parcentage value calculation is fixed so the value is rounded - rather than floored. --- src/chartjs-plugin-labels.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/chartjs-plugin-labels.js b/src/chartjs-plugin-labels.js index 7a646d7..8e35ca9 100644 --- a/src/chartjs-plugin-labels.js +++ b/src/chartjs-plugin-labels.js @@ -265,7 +265,11 @@ } else { percentage = element._view.circumference / this.chart.config.options.circumference * 100; } - percentage = parseFloat(percentage.toFixed(this.options.precision)); + percentage = parseFloat(Math.round(percentage * Math.pow(10, this.options.precision)) / Math.pow(10, this.options.precision)); + + + + if (!this.options.showActualPercentages) { if (this.chart.config.type === 'bar') { this.totalPercentage = this.barTotalPercentage[index] || 0; @@ -273,7 +277,7 @@ this.totalPercentage += percentage; if (this.totalPercentage > 100) { percentage -= this.totalPercentage - 100; - percentage = parseFloat(percentage.toFixed(this.options.precision)); + percentage = parseFloat(Math.round(percentage * Math.pow(10, this.options.precision)) / Math.pow(10, this.options.precision)); } if (this.chart.config.type === 'bar') { this.barTotalPercentage[index] = this.totalPercentage From 2ce718e0717717e06eaa76fa25d298df2177eaed Mon Sep 17 00:00:00 2001 From: "Mitsuki.Fukunaga" Date: Thu, 20 Jun 2019 12:19:44 +1000 Subject: [PATCH 2/2] code cleaned --- src/chartjs-plugin-labels.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/chartjs-plugin-labels.js b/src/chartjs-plugin-labels.js index 8e35ca9..1f887fa 100644 --- a/src/chartjs-plugin-labels.js +++ b/src/chartjs-plugin-labels.js @@ -267,9 +267,6 @@ } percentage = parseFloat(Math.round(percentage * Math.pow(10, this.options.precision)) / Math.pow(10, this.options.precision)); - - - if (!this.options.showActualPercentages) { if (this.chart.config.type === 'bar') { this.totalPercentage = this.barTotalPercentage[index] || 0;