Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught reference error - function is not defined

function generatePieChart(chartData, counter='', diffSeparator=''){     
  var chart;
  var legend;

//chartData = "["+chartData+"]";                        

AmCharts.ready(function () {
    // PIE CHART
    chart = new AmCharts.AmPieChart();
    chart.dataProvider = chartData;
    chart.titleField = "stage";
    chart.valueField = "enquiryCount";
    chart.depth3D = 10;
    chart.angle = 10;

    // LEGEND
    legend = new AmCharts.AmLegend();
    legend.align = "center";
    legend.markerType = "circle";
    chart.balloonText = "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>";
    //chart.addLegend(legend);


    // WRITE
    chart.write("chart_div_"+diffSeparator+"_"+counter);
});


}

generatePieChart(<?=$data?>,'<?=$i?>','o');

I am trying to generate graphs as it needs to be generated 10 times. So, instead of placing the complete jquery, i created the generation section to a function as you can see. Then while calling the function, it is providing me error saying "Uncaught reference error". I also checked many of the post's describing different solution. I tried all of them but none of them worked. And the most annoying thing is that, the same script works in firefox but not in chrome.

like image 495
Ck Maurya Avatar asked Mar 14 '14 10:03

Ck Maurya


1 Answers

The following line is not valid JavaScript

function generatePieChart(chartData, counter='', diffSeparator='') {

Remove the ='' from the parameters.

The parameters will default to the datatypes of the values passed in to the function when it is called. Which in your example are strings anyway.

like image 91
Mark Walters Avatar answered Oct 14 '22 15:10

Mark Walters