admin管理员组

文章数量:1410697

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 plete 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.

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 plete 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.

Share Improve this question edited Mar 20, 2014 at 10:30 Mark Walters 12.4k6 gold badges35 silver badges48 bronze badges asked Mar 14, 2014 at 10:56 Ck MauryaCk Maurya 2,2552 gold badges20 silver badges27 bronze badges 2
  • 2 on a sidenote: what does this have to do with PHP exactly? Please don't tag questions with tags that don't have anything to do with it. – Tularis Commented Mar 14, 2014 at 11:04
  • @Tularis I agree, I guess the OP added this because the parameters to the function were PHP variables. I've removed this tag as it is misleading. – Mark Walters Commented Mar 14, 2014 at 11:15
Add a ment  | 

1 Answer 1

Reset to default 5

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.

本文标签: javascriptUncaught reference errorfunction is not definedStack Overflow