gpt4 book ai didi

google-visualization - 谷歌可视化 + jboss 接缝 2

转载 作者:行者123 更新时间:2023-12-04 05:15:12 26 4
gpt4 key购买 nike

我正在尝试在 jboss seam 2 项目中使用 google 可视化 api。

我创建了一个简单的例子,它实际上取自 Google Quick Start page .

<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);

// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>

当我在网络浏览器中将它作为文件打开时,它运行良好。但是当我将它放入我的 Jboss Seam 2 项目并在 Web 浏览器中打开时,它会在红色背景上生成一条错误消息“b[c] 未定义”。

这是我在浏览器中打开页面源代码时看到的:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script src="/MCMS/a4j/g/3_3_3.Final/org/ajax4jsf/framework.pack.js" type="text/javascript"></script>
<script src="/MCMS/a4j/g/3_3_3.Final/org/richfaces/ui.pack.js" type="text/javascript"></script>
<link class="component" href="/MCMS/a4j/s/3_3_3.Final/org/richfaces/skin.xcss/DATB/eAGTKJ8eErp8hjQADcsDKg__" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);

// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>

<body>

<div id="chart_div"></div>
</body>
</html>

正如您所看到的,Jboss Seam 为 a4j 添加了一些其他脚本 src。

a4j javascript 是否可能与 google 可视化 api javascript 冲突?

有什么想法如何解决这个问题吗?

最佳答案

终于在这里找到了解决方案

Google charts error:Cannot read property 'length' of undefined; Debugging error in Google Charts

在这里

http://code.google.com/p/google-visualization-api-issues/issues/detail?id=501 .

在脚本的开头添加以下 hack:

Array.prototype.reduce = undefined;

或更优雅地:
Array.prototype.reduce=function(fun){var len=this.length&#62;&#62;&#62;0;if(typeof fun!="function")throw new TypeError;if(len==0&#38;&#38;arguments.length==1)throw new TypeError;var i=0;if(arguments.length&#62;=2)var rv=arguments[1];else{do{if(i in this){var rv=this[i++];break}if(++i&#62;=len)throw new TypeError;}while(true)}for(;i&#60;len;i++)if(i in this)rv=fun.call(undefined,rv,this[i],i,this);return rv};

解决问题!

关于google-visualization - 谷歌可视化 + jboss 接缝 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14363224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com