Highcharts5 which implements JavaScript strict mode is not working when Locker Service is activated.
The chart renders when the Locker Service is deactivated.
But when the Locker Service is activated, it doesn't even fire the afterScriptsLoaded
, most probably because the Highcharts files are not Locker compatible. (But when I inspect, I can see the two files loaded in "Sources" tab in my Chrome browser).
Component code:-
<aura:component description="testComp" implements="force:appHostable,flexipage:availableForAllPageTypes">
<ltng:require scripts="{!join(',',
$Resource.namespace__highchartsv5 + '/script_highcharts/highcharts.src.js',
$Resource.namespace__highchartsv5 + '/script_highcharts/highcharts-more.src.js'
)}"
afterScriptsLoaded="{!c.scriptsLoaded}" />
<div aura:id="chartComponent" id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</aura:component>
highcharts.src.js - https://code.highcharts.com/highcharts.src.js
highcharts-more.src.js - https://code.highcharts.com/highcharts-more.src.js
Controller:-
({
scriptsLoaded : function(component, event, helper){
helper.drawChart(component);
}
})
Helper:-
({
drawChart : function(component) {
var stackedColumnChart = new Highcharts.Chart({
chart : {
type: 'column',
renderTo : component.find("chartComponent").getElement()
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
}
})
rerender
inside the renderer.