mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Fix stacking bug when a dataset is removed (#8520)
This commit is contained in:
parent
b06cd36697
commit
8796a1ba1d
@ -107,6 +107,7 @@ class Chart {
|
||||
this._options = options;
|
||||
this._layers = [];
|
||||
this._metasets = [];
|
||||
this._stacks = undefined;
|
||||
this.boxes = [];
|
||||
this.currentDevicePixelRatio = undefined;
|
||||
this.chartArea = undefined;
|
||||
@ -370,8 +371,11 @@ class Chart {
|
||||
*/
|
||||
_removeUnreferencedMetasets() {
|
||||
const me = this;
|
||||
const datasets = me.data.datasets;
|
||||
me._metasets.forEach((meta, index) => {
|
||||
const {_metasets: metasets, data: {datasets}} = me;
|
||||
if (metasets.length > datasets.length) {
|
||||
delete me._stacks;
|
||||
}
|
||||
metasets.forEach((meta, index) => {
|
||||
if (datasets.filter(x => x === meta._dataset).length === 0) {
|
||||
me._destroyDatasetMeta(index);
|
||||
}
|
||||
|
||||
102
test/fixtures/controller.bar/stacking/remove-dataset.js
vendored
Normal file
102
test/fixtures/controller.bar/stacking/remove-dataset.js
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
var barChartData = {
|
||||
labels: [0, 1, 2, 3, 4, 5, 6],
|
||||
datasets: [
|
||||
{
|
||||
backgroundColor: 'red',
|
||||
data: [
|
||||
// { x: 0, y: 0 },
|
||||
{x: 1, y: 5},
|
||||
{x: 2, y: 5},
|
||||
{x: 3, y: 5},
|
||||
{x: 4, y: 5},
|
||||
{x: 5, y: 5},
|
||||
{x: 6, y: 5}
|
||||
]
|
||||
},
|
||||
{
|
||||
backgroundColor: 'blue',
|
||||
data: [
|
||||
{x: 0, y: 5},
|
||||
// { x: 1, y: 0 },
|
||||
{x: 2, y: 5},
|
||||
{x: 3, y: 5},
|
||||
{x: 4, y: 5},
|
||||
{x: 5, y: 5},
|
||||
{x: 6, y: 5}
|
||||
]
|
||||
},
|
||||
{
|
||||
backgroundColor: 'green',
|
||||
data: [
|
||||
{x: 0, y: 5},
|
||||
{x: 1, y: 5},
|
||||
// { x: 2, y: 0 },
|
||||
{x: 3, y: 5},
|
||||
{x: 4, y: 5},
|
||||
{x: 5, y: 5},
|
||||
{x: 6, y: 5}
|
||||
]
|
||||
},
|
||||
{
|
||||
backgroundColor: 'yellow',
|
||||
data: [
|
||||
{x: 0, y: 5},
|
||||
{x: 1, y: 5},
|
||||
{x: 2, y: 5},
|
||||
// {x: 3, y: 0 },
|
||||
{x: 4, y: 5},
|
||||
{x: 5, y: 5},
|
||||
{x: 6, y: 5}
|
||||
]
|
||||
},
|
||||
{
|
||||
backgroundColor: 'purple',
|
||||
data: [
|
||||
{x: 0, y: 5},
|
||||
{x: 1, y: 5},
|
||||
{x: 2, y: 5},
|
||||
{x: 3, y: 5},
|
||||
// { x: 4, y: 0 },
|
||||
{x: 5, y: 5},
|
||||
{x: 6, y: 5}
|
||||
]
|
||||
},
|
||||
{
|
||||
backgroundColor: 'grey',
|
||||
data: [
|
||||
{x: 0, y: 5},
|
||||
{x: 1, y: 5},
|
||||
{x: 2, y: 5},
|
||||
{x: 3, y: 5},
|
||||
{x: 4, y: 5},
|
||||
// { x: 5, y: 0 },
|
||||
{x: 6, y: 5}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
type: 'bar',
|
||||
data: barChartData,
|
||||
options: {
|
||||
scales: {
|
||||
x: {
|
||||
display: false,
|
||||
stacked: true
|
||||
},
|
||||
y: {
|
||||
display: false,
|
||||
stacked: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
options: {
|
||||
run(chart) {
|
||||
chart.data.datasets.splice(0, 1);
|
||||
chart.update();
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/stacking/remove-dataset.png
vendored
Normal file
BIN
test/fixtures/controller.bar/stacking/remove-dataset.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Loading…
x
Reference in New Issue
Block a user