Re: [visualization-api] Object has no method getColumnType

244 views
Skip to first unread message

Sergey Grabkovsky

unread,
Nov 16, 2012, 11:59:54 AM11/16/12
to google-visua...@googlegroups.com
Hello, charts cannot currently be rendered straight from json data, so you need to create a DataTable from it first. I'm not sure if your json data will fit the DataTable format, but if not, then you need to massage it so it does. You can see all the different ways of creating a DataTable in these docs.

- Sergey


On Fri, Nov 16, 2012 at 11:47 AM, jdv590 <vica...@muohio.edu> wrote:
I am trying to fill a line chart with JSON data via ajax from an asp.net web service.  When I run my code I get an error saying:

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


 I have attached a snapshot of the error message, as well as a text file with the JSON data.  My code is below:

  <script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type="text/javascript">
       
            google.load("visualization", "1", { packages: ["corechart"] });
            google.setOnLoadCallback(drawChart);
           // $(document).ready(function () {
                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>

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/mrciGOVClzMJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

asgallant

unread,
Nov 16, 2012, 1:16:12 PM11/16/12
to google-visua...@googlegroups.com
Your JSON isn't in the right format for the Visualization API, so you would either need to change the JSON format or manually build a DataTable using the data in your JSON.  Either way, you need to have a DataTable object to draw the charts with.  Here's a quick-and-dirty conversion for you: http://jsfiddle.net/asgallant/2MxnR/

Note that the chart looks weird because your data isn't in chronological order, to fix that you can sort the DataTable after building it: http://jsfiddle.net/asgallant/2MxnR/1/
Reply all
Reply to author
Forward
0 new messages