I am trying to use Highchart js (https://code.highcharts.com/highcharts.js) in my LWC component for Chart, but getting error: TypeError: e.chart is not a function
I am not able to figure out what exactly I am missing, am Using Highchart demo code from documentation. Any help would be appreciated..
JS file:
import { LightningElement } from 'lwc';
import HIGHCHARTS from "@salesforce/resourceUrl/highchart";
import { loadScript} from "lightning/platformResourceLoader";
export default class RKMHighChart extends LightningElement {
renderedCallback(){
loadScript(this, HIGHCHARTS)
.then(() => {
console.log('High Charts Loaded');
this.runHighcharts();
})
.catch(error => console.log('Error occured: ', error))
}
runHighcharts() {
const container = this.template.querySelector('.container-class');
HIGHCHARTS.chart(container, {
title: {
text: "Logarithmic axis demo"
},
xAxis: {
tickInterval: 1,
type: "logarithmic",
accessibility: {
rangeDescription: "Range: 1 to 10"
}
},
yAxis: {
type: "logarithmic",
minorTickInterval: 0.1,
accessibility: {
rangeDescription: "Range: 0.1 to 1000"
}
},
tooltip: {
headerFormat: "<b>{series.name}</b><br />",
pointFormat: "x = {point.x}, y = {point.y}"
},
series: [
{
data: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],
pointStart: 1
}
]
});
}
}
html file:
<template>
Chart.. <br/>
<div id="container" class="container-class" style="width:100%; height:400px;"></div>
</template>
loadScript(this, HIGHCHARTS + "/highcharts.js")
, but that depends on how the directory structure of the ZIP folder uploaded as static resource. (2) Also, I guess it should behighcharts.chart(...)
and notHIGHCHARTS.chart(...)
. JS is case-sensitive and if I'm not mistakenHIGHCHARTS
just points to the static resource location for loading it (not the actual JS file).