"Table has no columns "- by asp.net for Google chart// Please Help and Thanks! -candy

37 views
Skip to first unread message

candy

unread,
Jul 10, 2016, 10:30:20 PM7/10/16
to Google Visualization API
Hello, 
I get the   "Table has no columns " on get json by asp.net for Google chart.
Could you help me here please ...?  Thank you all! I am stuck here. 

Method (1) I test the  Url  for directly to Json on my iis  EX:   http://localhost/candy_json_D3/sampleData.json   => fail 
Method (2) I use the  Url  asp.net   public string GetChartData()  =>"Table has no columns "
        
          {    return JsonString;
        }

--------------------------------------------------------------------------------------------------------------------------------------------------------

I. sampleData.json
{
  "cols": [
        {"id":"","label":"Topping","pattern":"","type":"string"},
        {"id":"","label":"Slices","pattern":"","type":"number"}
      ],
  "rows": [
        {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},
        {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},
        {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},
        {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},
        {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]}
      ]
}
------------------------------------------------------------------------------------------------------------------------------------
II. <script type="text/javascript">

        // Load the Visualization API and the piechart package.
        google.charts.load('current', { 'packages': ['corechart'] });

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

        function drawChart() {
            var jsonData = $.ajax({
                url: "ColumnChart.aspx/GetChartData",     // how could I read it it get the right type here ?
                dataType: "json",
                data: '{}',
                success: function (response) {
                    drawchart(response.d); // calling method  
                },

                error: function () {
                    alert("Error loading data! Please try again.");
                }
                //async: false
            }).responseText;

            // 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.PieChart(document.getElementById('chart_div'));
            chart.draw(data, { width: 400, height: 240 });
        }
    </script>
----------------------------------------------------------------------------------------------------
III. Asp.net 
 public string GetChartData()
        { 
           // Get data from "http://localhost/candy_json_D3/sampleData.json "
            return JsonString;
        }


BR
Candy
Reply all
Reply to author
Forward
0 new messages