diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index dbf08e77f2b..81d865810e4 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -192,13 +192,18 @@ function createDataContext(parent, index, element) { } function clearStacks(meta, items) { + const axis = meta.vScale && meta.vScale.axis; + if (!axis) { + return; + } + items = items || meta._parsed; for (const parsed of items) { const stacks = parsed._stacks; - if (!stacks || stacks[meta.vScale.id] === undefined || stacks[meta.vScale.id][meta.index] === undefined) { + if (!stacks || stacks[axis] === undefined || stacks[axis][meta.index] === undefined) { return; } - delete stacks[meta.vScale.id][meta.index]; + delete stacks[axis][meta.index]; } } diff --git a/test/fixtures/controller.bar/stacking/issue-9105.js b/test/fixtures/controller.bar/stacking/issue-9105.js new file mode 100644 index 00000000000..200ce4d30a8 --- /dev/null +++ b/test/fixtures/controller.bar/stacking/issue-9105.js @@ -0,0 +1,49 @@ +module.exports = { + description: 'https://github.com/chartjs/Chart.js/issues/9105', + config: { + type: 'bar', + data: { + labels: ['January', 'February', 'March', 'April', 'May', 'June'], + datasets: [ + { + backgroundColor: 'rgba(255,99,132,0.8)', + label: 'Dataset 1', + data: [12, 19, 3, 5, 2, 3], + stack: '0', + yAxisID: 'y-axis-1' + }, + { + backgroundColor: 'rgba(54,162,235,0.8)', + label: 'Dataset 2', + data: [13, 19, 3, 5, 8, 3], + stack: '0', + yAxisID: 'y-axis-1' + }, + { + backgroundColor: 'rgba(75,192,192,0.8)', + label: 'Dataset 3', + data: [13, 19, 3, 5, 8, 3], + stack: '0', + yAxisID: 'y-axis-1' + } + ] + }, + options: { + plugins: false, + scales: { + xaxis: { + display: false, + }, + 'y-axis-1': { + display: false + } + } + } + }, + options: { + run(chart) { + chart.data.datasets[1].stack = '1'; + chart.update(); + } + } +}; diff --git a/test/fixtures/controller.bar/stacking/issue-9105.png b/test/fixtures/controller.bar/stacking/issue-9105.png new file mode 100644 index 00000000000..14a21682680 Binary files /dev/null and b/test/fixtures/controller.bar/stacking/issue-9105.png differ