I was able to get a working test chart using ChartJS but I'm having trouble with the Frappe Gantt library.
Right now it's throwing an error in the catch, but I think the error is null as I'm getting
Cannot read property 'message' of undefined
If I force it to call Initializechartjs(), I then get
Gantt is not defined
I can see all 4 resources loading -
Here is my code
chart.html
<template>
<lightning-card title="Gantt">
<svg class="gantt" width="400" height="450" lwc:dom="manual"></svg>
</lightning-card>
</template>
chart.js
import { LightningElement,api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import momentJS from '@salesforce/resourceUrl/momentJS';
import snapSVG from '@salesforce/resourceUrl/snapSVG';
import frappeGanttMin from '@salesforce/resourceUrl/frappeGanttMin';
import frappeGanttStyle from '@salesforce/resourceUrl/frappeGanttStyle';
export default class Chartcmp extends LightningElement {
@api chartjsInitialized = false;
@api recordId;
renderedCallback() {
if (this.chartjsInitialized) {
return;
}
this.chartjsInitialized = true;
console.log('chart loading');
Promise.all([
loadScript(this, momentJS),
loadScript(this, snapSVG),
loadScript(this, frappeGanttMin),
loadStyle(this, frappeGanttStyle)
])
.then(() => {
this.Initializechartjs();
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading chart',
message: error.message,
variant: 'error'
})
);
});
}
Initializechartjs() {
console.log("loaded");
//Get the context of the canvas element we want to select
var chartClass = this.template.querySelector(".gantt");
var gantt = new Gantt(chartClass ,{
tasks: [
{
id: 'Task 1',
name: 'Redesign website',
start: '2016-12-28',
end: '2016-12-31',
},
{
id: 'Task 2',
name: 'Second Task',
start: '2016-12-29',
end: '2016-12-30',
}
]
});
}
}