From 98c81f0c9dae8eea310f50b09a3d10d74d03d510 Mon Sep 17 00:00:00 2001 From: Pierre-Gilles Leymarie Date: Mon, 5 Aug 2024 10:26:23 +0200 Subject: [PATCH] Dashboard: Fix charts with lots of zeros (#2105) --- front/src/components/boxs/chart/ApexChartAreaOptions.js | 9 ++++++++- front/src/components/boxs/chart/ApexChartBarOptions.js | 9 ++++++++- front/src/components/boxs/chart/ApexChartLineOptions.js | 9 ++++++++- .../components/boxs/chart/ApexChartStepLineOptions.js | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/front/src/components/boxs/chart/ApexChartAreaOptions.js b/front/src/components/boxs/chart/ApexChartAreaOptions.js index a18875760a..31cb56bc68 100644 --- a/front/src/components/boxs/chart/ApexChartAreaOptions.js +++ b/front/src/components/boxs/chart/ApexChartAreaOptions.js @@ -51,7 +51,14 @@ const getApexChartAreaOptions = ({ displayAxes, height, series, colors, locales, }, yaxis: { labels: { - padding: 4 + padding: 4, + formatter: function(value) { + if (Math.abs(value) < 1) { + return value; // For very low values, like crypto prices, use the normal value + } else { + return value.toFixed(2); // 2 decimal places for other values + } + } } }, colors, diff --git a/front/src/components/boxs/chart/ApexChartBarOptions.js b/front/src/components/boxs/chart/ApexChartBarOptions.js index 43705a389e..f26de7d78d 100644 --- a/front/src/components/boxs/chart/ApexChartBarOptions.js +++ b/front/src/components/boxs/chart/ApexChartBarOptions.js @@ -59,7 +59,14 @@ const getApexChartBarOptions = ({ displayAxes, series, colors, locales, defaultL }, yaxis: { labels: { - padding: 4 + padding: 4, + formatter: function(value) { + if (Math.abs(value) < 1) { + return value; // For very low values, like crypto prices, use the normal value + } else { + return value.toFixed(2); // 2 decimal places for other values + } + } } }, colors, diff --git a/front/src/components/boxs/chart/ApexChartLineOptions.js b/front/src/components/boxs/chart/ApexChartLineOptions.js index 990a92ee80..24a9f2365d 100644 --- a/front/src/components/boxs/chart/ApexChartLineOptions.js +++ b/front/src/components/boxs/chart/ApexChartLineOptions.js @@ -50,7 +50,14 @@ const getApexChartLineOptions = ({ height, displayAxes, series, colors, locales, }, yaxis: { labels: { - padding: 4 + padding: 4, + formatter: function(value) { + if (Math.abs(value) < 1) { + return value; // For very low values, like crypto prices, use the normal value + } else { + return value.toFixed(2); // 2 decimal places for other values + } + } } }, colors, diff --git a/front/src/components/boxs/chart/ApexChartStepLineOptions.js b/front/src/components/boxs/chart/ApexChartStepLineOptions.js index b6b695e100..5cac219c71 100644 --- a/front/src/components/boxs/chart/ApexChartStepLineOptions.js +++ b/front/src/components/boxs/chart/ApexChartStepLineOptions.js @@ -49,7 +49,14 @@ const getApexChartStepLineOptions = ({ height, displayAxes, series, colors, loca }, yaxis: { labels: { - padding: 4 + padding: 4, + formatter: function(value) { + if (Math.abs(value) < 1) { + return value; // For very low values, like crypto prices, use the normal value + } else { + return value.toFixed(2); // 2 decimal places for other values + } + } } }, colors,