Cannot read preporties of undefined (reading 'register') at chartjs-plugin-annotationLine.js срочно нужна помощь
Всем здравствуйте!Мне нужна помощь!
const annotationLinePlugin = {
renderAnnotationLine: function(chartInstance, line) {
let datasetMeta = chartInstance.getDatasetMeta(line.datasetIndex);
let context = chartInstance.chart.ctx;
let datasetModel = datasetMeta.data[line.dataIndex]._model;
const xBarCenter = datasetModel.x
const barWidth = datasetModel.width;
const xStart = xBarCenter - (barWidth / 2) - 4;
const xEnd = xBarCenter + (barWidth / 2) + 4;
const yAxisID = datasetMeta.yAxisID;
const yCoordinate = chartInstance.scales[yAxisID].getPixelForValue(line.yCoordinate);
context.beginPath();
context.strokeStyle = line.color;
context.lineWidth = line.width;
context.moveTo(xStart, yCoordinate);
context.lineTo(xEnd, yCoordinate);
context.stroke();
if (typeof line.label !== typeof undefined) {
context.textAlign = 'center';
context.fillStyle = line.color;
context.fillText(line.label, yCoordinate, xEnd + 7);
}
},
afterDatasetsDraw: function(chart, easing) {
if (chart.data.datasets.length < 1) {
return;
}
if (chart.config.lines) {
chart.config.lines.map(line => {
this.renderAnnotationLine(chart, line);
});
}
}
};
Chart.plugins.register(annotationLinePlugin);
В браузере выдаёт ошибку :
Uncaught TypeError :
Cannot read preporties of undefined (reading 'register')
at chartjs-plugin-annotationLine.js:42:15
Ответы (1 шт):
Автор решения: XelaNimed
→ Ссылка
Описание ошибки говорит Вам, что у объекта Chart свойство plugins undefined, что означает либо его полное отсутствие, либо что его значение не было проинициализированно. Вы смотрили на доступные свойства объекта Chart в дебагере?
На официальном сайте библиотеки Chart.js размещенна информация о миграции на версию 3, согласно которой:
Chart.pluginsбыл заменен наChart.registry. Значения плагина по умолчанию теперь находятся в форматеChart.defaults.plugins[id]