The error is Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. HTML Code:
<template>
<div class = 'slds-box' >
<canvas class="line-chart" width="800" height="450" lwc:dom="manual"></canvas>
</div>
</template>
JSCode
import { LightningElement,api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import chart from '@salesforce/resourceUrl/chart';
export default class Chartcmp extends LightningElement {
@api chartjsInitialized = false;
@api recordId;
renderedCallback() {
if (this.chartjsInitialized) {
return;
}
this.chartjsInitialized = true;
console.log('chartjs loading');
Promise.all([
loadScript(this, chart + '/chart/Chart.min.js')
])
.then(() => {
this.Initializechartjs();
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading chartJs',
message: error.message,
variant: 'error'
})
);
});
}
Initializechartjs() {
console.log("loaded");
//Get the context of the canvas element we want to select
var ctx = this.template.querySelector(".line-chart");
var lineChart = new Chart(ctx ,{
type: 'line',
data: {
labels: ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
datasets: [
{
label:'Day',
data: [110, 290, 150, 250, 500, 420, 100],
borderColor:'rgba(62, 159, 222, 1)',
fill: false,
pointBackgroundColor: "#FFFFFF",
pointBorderWidth: 4,
pointHoverRadius: 5,
pointRadius: 3,
bezierCurve: true,
pointHitRadius: 10
}
]
},
options: {
legend: {
position: 'bottom',
padding: 10,
},
responsive: true
}
});
}
}