简体   繁体   English

未捕获的引用错误 - 未定义函数

[英]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. 我正在尝试生成图形,因为它需要生成10次。 So, instead of placing the complete jquery, i created the generation section to a function as you can see. 因此,我没有放置完整的jquery,而是创建了一个函数的生成部分,如您所见。 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. 最令人讨厌的是,同样的脚本在firefox中运行,但在chrome中不起作用。

The following line is not valid JavaScript 以下行不是有效的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. 无论如何,在你的例子中是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM