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

标签 google-visualization jboss-seam

我正在尝试在 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/

相关文章:

javascript - polymer 1.x : Resizing chart after page load

ruby-on-rails - 如何使用 googlecharts gem?

html - 如何通过ajax从url中的google图表发送值?

php - Google Chart - 如何使用 php 变量来更改数据源

jsf - ConvertDateTime 未获取 web.xml 中定义的时区

google-visualization - 如何设置工具提示以显示百分比以匹配 Google 可视化折线图中的轴?

java - 在Seam项目中使用模拟服务

java - 接缝导航规则。捕获所有无效 URL 并重定向到 404 页面

java - 调用seam组件中的私有(private)方法