Skip to content

Commit

Permalink
Merge pull request #1 from weuceda14/weuceda14-patch-1
Browse files Browse the repository at this point in the history
Update WidgetChart.jsx so that the bar chart displays correct Y value…
  • Loading branch information
weuceda14 authored Dec 4, 2024
2 parents 80b7ceb + f436693 commit 4d429ab
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions web/client/components/charts/WidgetChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4d429ab

Please sign in to comment.