i have conducted some little research and if you want the data bars to be sorted for each year part of these clusters you need to pre define the dataset and sort it like this:
const chartData = {
datasets: [
{
label: "Respondent 1",
data: [750, 700, null, null],
backgroundColor: "#1E81D3",
borderColor: "#ccc",
borderRadius: 5
},
{
label: "Respondent 3",
data: [null, 419, null, null],
backgroundColor: "#0D5AB7",
borderColor: "#ccc",
borderRadius: 5
},
{
label: "Respondent 2",
data: [null, 33921, null, null],
backgroundColor: "#063F84",
borderColor: "#ccc",
borderRadius: 5
},
{
label: "Respondent 3",
data: [null, null, 21583, null],
backgroundColor: "#0D5AB7",
borderColor: "#ccc",
borderRadius: 5
},
{
label: "Respondent 2",
data: [null, null, 20001, null],
backgroundColor: "#063F84",
borderColor: "#ccc",
borderRadius: 5
},
{
label: "Respondent 3",
data: [null, null, null, 488],
backgroundColor: "#0D5AB7",
borderColor: "#ccc",
borderRadius: 5
},
{
label: "Respondent 2",
data: [null, null, null, 3999],
backgroundColor: "#063F84",
borderColor: "#ccc",
borderRadius: 5
}
],
labels: [
"2017 Fiscal Year (Jul-Jun) - H2",
"2022 Fiscal Year (Jan-Dec) - H2",
"2023 Fiscal Year (Jan-Dec) - H1",
"2023 Fiscal Year (Jan-Dec) - H2"
],
yAxisLabel: "Cubic Meters"
};
// Sort datasets based on the sum of their `data` values
chartData.datasets.sort((a, b) => {
const sumA = a.data.reduce((sum, val) => sum + (val || 0), 0); // Calculate sum of dataset A
const sumB = b.data.reduce((sum, val) => sum + (val || 0), 0); // Calculate sum of dataset B
return sumB - sumA; // Sort in descending order
});
if i understood you question correctly this would probably be the solution if not please give some clarification of what is wrong with the answer.