对象有没有方法getColumnType错误 [英] Object has no method getColumnType error

查看:352
本文介绍了对象有没有方法getColumnType错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读这文章,但似乎无法把它适合我的问题。我使用谷歌图表建立一个折线图。 x轴是一个日期,y轴为整数。

当我运行我的code我得到一个大错误信息


  

{对象则列出了所有我的JSON格式的数据}没有方法'getColumnType。


我从Web服务通过Ajax调用让我的JSON图表数据。我的code到目前为止

 <脚本类型=文/ JavaScript的>            的google.load(可视化,1,{软件包:[corechart]});
            google.setOnLoadCallback(drawChart);
            功能drawChart(){
                VAR jsonData = $阿贾克斯({
                    网址:WebService.asmx / HelloWorld的,
                    数据:{},
                    的contentType:应用/ JSON的;字符集= UTF-8,
                    数据类型:JSON
                    异步:假的
                })responseText的;                VAR的选择= {
                    标题:公司业绩
                };                VAR图=新google.visualization.LineChart(的document.getElementById('chart_div1'));
                chart.draw(jsonData,期权);
            }
    < / SCRIPT>


解决方案

解决方法很简单....你不能直接从JSON数据填补谷歌的图表。该JSON首先需要格式化成一个DataTable。该解决方案是这样的:

  //加载可视化API和饼图包。
          的google.load('可视化','1',{'包':['annotatedtimeline']});          //设置回调加载谷歌可视化API时运行。
          google.setOnLoadCallback(drawChart);          功能drawChart(){
              VAR jsonData = $阿贾克斯({
                  网址:JSON.txt
                  数据类型:JSON
                  异步:假的
              })responseText的;              //这里是FIX!创建我们的数据表了从服务器加载JSON数据。
              VAR数据=新google.visualization.DataTable(jsonData);              //实例并绘制图表我们,传递一些选项。
              VAR图=新google.visualization.AnnotatedTimeLine(的document.getElementById('chart_div1'));
              chart.draw(数据,{宽度:400,高度:240});
          }

I have read the solution on this post but cannot seem to fit it to my issue. I am using google charts to build a line chart. x-axis being a date, y-axis being an integer.

When I run my code I get a large error message

Object {"it then lists all my JSON formatted data"} has no method 'getColumnType'.

I am getting my JSON chart data from a web service via an AJAX call. My code so far

<script type="text/javascript">

            google.load("visualization", "1", { packages: ["corechart"] });
            google.setOnLoadCallback(drawChart);


            function drawChart() {
                var jsonData = $.ajax({
                    url: "WebService.asmx/HelloWorld",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: false
                }).responseText;

                var options = {
                    title: 'Company Performance'
                };

                var chart = new google.visualization.LineChart(document.getElementById('chart_div1'));
                chart.draw(jsonData, options);
            }


    </script>

解决方案

the solution is simple....You cannot fill a google chart directly from JSON data. The JSON first needs to be formatted into a datatable. the solution looks like this:

  // Load the Visualization API and the piechart package.
          google.load('visualization', '1', { 'packages': ['annotatedtimeline'] });

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

          function drawChart() {
              var jsonData = $.ajax({
                  url: "JSON.txt",
                  dataType: "json",
                  async: false
              }).responseText;

              // HERE IS THE FIX!!! Create our data table out of JSON data loaded from server.
              var data = new google.visualization.DataTable(jsonData);

              // Instantiate and draw our chart, passing in some options.
              var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div1'));
              chart.draw(data, { width: 400, height: 240 });
          }

这篇关于对象有没有方法getColumnType错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆