This is a method in component file
graphGenerate(){
let dataPoints = [
{ y: this.usa, name: "USA" },
{ y: this.china, name: "China" },
{ y: this.india, name: "India" }
];
let chart = new CanvasJS.Chart("chartContainer", {
theme: "light2",
animationEnabled: true,
exportEnabled: true,
title:{
text: "Country Population"
},
data: [{
type: "pie",
showInLegend: true,
toolTipContent: "<b>{name}</b>: ${y} (#percent%)",
indexLabel: "{name} - #percent%",
dataPoints : this.datapoints
}]
});
chart.render();
}
This is how my HTML code looks like
<div class="col-md-12 text-center">
<button (click)="graphGenerate()" class="btn btn-primary btn-xl btn-analyse" >Pie Chart</button>
<div id="chartContainer" style="height: 370px; width: 100%; margin-left:auto;margin-right:auto;"></div>
</div>
When I click the button, my browser crashes and it does not generate the graph. Problem starts when executing chart.render()
line. No error either. What am doing wrong?