mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-06 16:26:52 +01:00
Clear stacks when data is replaced (#8617)
This commit is contained in:
@@ -178,12 +178,13 @@ function createDataContext(parent, index, point, raw, element) {
|
||||
|
||||
function clearStacks(meta, items) {
|
||||
items = items || meta._parsed;
|
||||
items.forEach((parsed) => {
|
||||
if (parsed._stacks[meta.vScale.id] === undefined || parsed._stacks[meta.vScale.id][meta.index] === undefined) {
|
||||
for (const parsed of items) {
|
||||
const stacks = parsed._stacks;
|
||||
if (!stacks || stacks[meta.vScale.id] === undefined || stacks[meta.vScale.id][meta.index] === undefined) {
|
||||
return;
|
||||
}
|
||||
delete parsed._stacks[meta.vScale.id][meta.index];
|
||||
});
|
||||
delete stacks[meta.vScale.id][meta.index];
|
||||
}
|
||||
}
|
||||
|
||||
const isDirectUpdateMode = (mode) => mode === 'reset' || mode === 'none';
|
||||
@@ -311,6 +312,7 @@ export default class DatasetController {
|
||||
if (me._data) {
|
||||
// This case happens when the user replaced the data array instance.
|
||||
unlistenArrayEvents(me._data, me);
|
||||
clearStacks(me._cachedMeta);
|
||||
}
|
||||
if (data && Object.isExtensible(data)) {
|
||||
listenArrayEvents(data, me);
|
||||
|
||||
50
test/fixtures/controller.bar/stacking/replace-data.js
vendored
Normal file
50
test/fixtures/controller.bar/stacking/replace-data.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
var barChartData = {
|
||||
labels: ['January', 'February', 'March'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Dataset 1',
|
||||
backgroundColor: 'red',
|
||||
data: [5, 5, 5]
|
||||
},
|
||||
{
|
||||
label: 'Dataset 2',
|
||||
backgroundColor: 'blue',
|
||||
data: [5, 5, 5]
|
||||
},
|
||||
{
|
||||
label: 'Dataset 3',
|
||||
backgroundColor: 'green',
|
||||
data: [5, 5, 5]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
description: 'https://github.com/chartjs/Chart.js/issues/8614',
|
||||
config: {
|
||||
type: 'bar',
|
||||
data: barChartData,
|
||||
options: {
|
||||
scales: {
|
||||
x: {
|
||||
display: false,
|
||||
stacked: true
|
||||
},
|
||||
y: {
|
||||
display: false,
|
||||
stacked: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
options: {
|
||||
run(chart) {
|
||||
chart.data.datasets[1].data = [
|
||||
{x: 'January', y: 5},
|
||||
// Februay missing
|
||||
{x: 'March', y: 5}
|
||||
];
|
||||
chart.update();
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/stacking/replace-data.png
vendored
Normal file
BIN
test/fixtures/controller.bar/stacking/replace-data.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.3 KiB |
Reference in New Issue
Block a user