I am trying to sets up a chart using the Chart.js library, which is uploaded as a static resource, I am getting the below error:
ReferenceError: require is not defined throws at https://karima-dev-ed.lightning.force.com/auraFW/javascript/aJdnlGe7HlLtzbzu8ssZ-A/aura_prod.js line 24 > eval:16:5
<ltng:require scripts="{!$Resource.chart}" afterScriptsLoaded="{!c.setup}"/>
<canvas aura:id="chart" id="myChart" width="400" height="400"/>
setup : function(component, event, helper) {
var data = {
labels: ["January", "February", "March"],
datasets: [{ data: [65, 59, 80, 81, 56, 55, 40] }]
};
var el = component.find("chart").getElement();
var ctx = el.getContext("2d");
var myNewChart = new Chart(ctx).Line(data);
}
Best Answer
It sounds like you need require.js. You'll need to download the minified version, upload it, and then include both of them: