Chartjs Controller
Chartjs Controller
action.setParams({"dataProviderName":component.get("v.apexDataProvider")});
action.setCallback(this, function(a){
var response = a.getReturnValue();
if (response == null || response == "" || response == "[]" ||
response == "{}"){
component.set("v.isChartDataEmpty", true);
return;
} else {
component.set("v.isChartDataEmpty", false);
}
helper.drawChart(component, JSON.parse(response), {});
});
$A.enqueueAction(action);
} else {
helper.drawChart(component, chartData, {});
}
},
////
// changeChartType is triggered when ChartTypeChange event is fired.
changeChartType : function(component, event, helper){
// Retrieve target component id and this component's global id.
// If this component instance is not target, exit.
var globalId = component.getGlobalId();
if (globalId != event.getParam("componentId")){
return;
}
// Draw new chart with new chart type and existing chart data & option.
var ctx = document.getElementById(globalId + "_chart").getContext("2d");
chart = new Chart(ctx)[event.getParam("chartType")]
(component.get("v.chartData"), component.get("v.chartOption"));