Chartjs-Chart.js how to align grouped bar chart correctly?

1👍

I believe your dataset is wrongly structured.

For stacked bar chart, the structure should be like this:

"datasets": [{
    "label": "MY",
    "stack": "stack1",
    "backgroundColor": "#f9aabd",
    "data": [2, 2, 22]
}, {
    "label": "ID",
    "stack": "stack1",
    "backgroundColor": "#ff980070",
    "data": [41, 64, 25]
}, {
    "label": "PH",
    "stack": "stack1",
    "backgroundColor": "#cce1f3",
    "data": [26, 3, 0]
}]

For each "country code" (MY, ID, PH), there should be one object. The values for the months are specified in the data array respectively.

The stack attribute specifies name of the stack in the particular month. If you specify more stacks, there will be more columns for each of the months.

Leave a comment