0π
this.barChartOptions.annotation.annotations
is not an array. Itβs another object like in the example
const options = {
plugins: {
autocolors: false,
annotation: {
annotations: {
line1: {
type: 'line',
yMin: 60,
yMax: 60,
borderColor: 'rgb(255, 99, 132)',
borderWidth: 2,
}
}
}
}
};
So to add a new annotation, you need to add an object and not push an array element.
For example you get the number of annotations already in the object with
let annotationsCount = Object.entries(this.barChartOptions.annotation.annotations)
Then you can add a new element with
this.barChartOptions.annotation.annotations[annotationsCount] = yourNewAnnotationObject
annotationCount can be anything. It is just the key of the new object like line1 in the example Using the number of objects already inside is just a suggestion. BUT it has to be unique, otherwise you overwrite an existing and not adding a new one
0π
You can try to set drawTime
property
annotation: {
drawTime: 'afterDatasetsDraw',
annotations: [....]
}
- [Chartjs]-How to include Chart.js in my AngularJS project?
- [Chartjs]-Add all data in the tooltip of Chart JS
Source:stackexchange.com