Display total amount in bar chart
Hello everyone,
I'm using kresus for a month and all the features are just amazing, thanks for all of your work !
However, I miss a little feature in bar charts: Display the total amount depending on the selected categories.
By looking at the source code, I found that you are using chartjs and I found a topic on stackoverflow that gave some code do to it. The topic can be found here and the code solution example here
I am not comfortable enough with react js and with MR process for now, so I feel not legit to open a good one, but I guess the solution in client/components/charts/category-barchart.tsx line 97 should be something like this :
container.current = new Chart(props.chartId, {
type: 'bar',
data: {
labels,
datasets,
},
options: {
tooltips: {
mode: 'label',
callbacks: {
footer: (tooltipItems, data) => {
// Original solution: let total = tooltipItems.reduce((a, e) => a + parseInt(e.yLabel), 0);
let total = round2(tooltipItems.reduce((a, b) => a + parseInt(b.yLabel), 0));
return 'Total: ' + total;
}
}
},
},
});
Thanks in advance for your consideration and have a good day !