From f436693f8b70a27b7291748c0da0853c88af53b3 Mon Sep 17 00:00:00 2001 From: weuceda14 <139005019+weuceda14@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:51:03 -0500 Subject: [PATCH] Update WidgetChart.jsx so that the bar chart displays correct Y value on the onhover element Recalculated how the onHover element for the bar chart is populated. Would sometimes take the first entry y value instead of adding it up for certain types of data. Now the onhover displays the accurate number for all bar charts --- web/client/components/charts/WidgetChart.jsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/web/client/components/charts/WidgetChart.jsx b/web/client/components/charts/WidgetChart.jsx index 5eed2f3979..7f9f72f5e1 100644 --- a/web/client/components/charts/WidgetChart.jsx +++ b/web/client/components/charts/WidgetChart.jsx @@ -278,9 +278,25 @@ const chartDataTypes = { }).filter(chart => chart !== null); } const sortedData = [...data].sort((a, b) => a[xDataKey] > b[xDataKey] ? 1 : -1); - const x = sortedData.map(d => d[xDataKey]); - const y = sortedData.map(d => d[yDataKey]); + + //changes that we made ********************************************************************** + const aggregatedData = sortedData.reduce((acc, item) => { + const xValue = item[xDataKey]; + const yValue = item[yDataKey]; + + if (!acc[xValue]) + acc[xValue] = 0; + acc[xValue] += yValue; // Summing up y-values for each unique x-value + return acc; + }, {}); + + const x = Object.keys(aggregatedData); + const y = Object.values(aggregatedData); + // const x = sortedData.map(d => d[xDataKey]); + // const y = sortedData.map(d => d[yDataKey]); + const name = traceName || yDataKey; + return { ...style, type: 'bar',