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

时间:2022-11-06 09:30:54
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.

我尝试生成图形,因为它需要生成10次。因此,我没有放置完整的jquery,而是将generation部分创建为一个函数。在调用该函数时,它提供了“未捕获引用错误”的错误。我也检查了很多描述不同解决方案的帖子。我试了所有的,但没有一个有效。最让人讨厌的是,同样的脚本在firefox中工作,但在chrome中却不行。

1 个解决方案

#1


5  

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.

当调用该函数时,参数将默认为传递给函数的值的数据类型。在你的例子中是字符串。

#1


5  

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.

当调用该函数时,参数将默认为传递给函数的值的数据类型。在你的例子中是字符串。