3 Replies - 161 Views - Last Post: 06 January 2017 - 12:11 PM

#1 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 92
  • Joined: 20-May 16

JavaScript runtime rror: Not an array

Posted 06 January 2017 - 09:39 AM

I am trying to recreate pie chart from following website: http://www.aspsnippe...-in-ASPNet.aspx

Error: Javascript runtime rror: Not an array

throw Error("Not an array");


Reports.aspx

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<script type="text/javascript">
    google.load("visualization", "1", { packages: ["corechart"] });
    google.setonloadCallback(drawChart);
    function drawChart() {
        var options = {
            title: 'USA City Distribution'
        };
        $.ajax({
            type: "POST",
            url: "Reports.aspx/GetChartData",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                var data = google.visualization.arrayToDataTable(r.d);
                var chart = new google.visualization.PieChart($("#chart")[0]);
                chart.draw(data, options);
            },
            failure: function (r) {
                alert(r.d);
            },
            error: function (r) {
                alert(r.d);
            }
        });
    }
</script>

  <div id="chart" style="width: 900px; height: 500px;">



Reports.aspx.vb

Partial Class UI_Reports
    Inherits System.Web.UI.Page
	
    <WebMethod()> _
    Public Shared Function GetChartData() As List(Of Object)
        Dim myConnectionString As String = "Server=MFCUSQL;Database=mydatabase;User Id=aaa;Password=aaa;"

        ' Connect to databse and open database file
        Dim da As SqlDataAdapter
        Dim ds As DataSet = New DataSet()
        Dim dt As DataTable = New DataTable
        Dim GetDataQuery As String = "SELECT Race, COUNT(ID) Total FROM [mytable];"
        Dim sqlConn As New SqlConnection(myConnectionString)
        Dim chartData As New List(Of Object)()
        chartData.Add(New Object() {"Race", "Total"})
        Try
            sqlConn.Open()

            Dim cmd1 = New SqlCommand(GetDataQuery, sqlConn)
            cmd1.CommandType = CommandType.Text
            cmd1.Connection = sqlConn
            Dim sdr As SqlDataReader = cmd1.ExecuteReader()
            While sdr.Read()
                chartData.Add(New Object() {sdr("Race"), sdr("Total")})
            End While

            sqlConn.Close()
        Catch ex As Exception
           
        End Try
    End Function
End Class

This post has been edited by ikhlas06: 06 January 2017 - 09:40 AM


Is This A Good Question/Topic? 0
  • +

Replies To: JavaScript runtime rror: Not an array

#2 astonecipher  Icon User is offline

  • Licensed PITA
  • member icon

Reputation: 2204
  • View blog
  • Posts: 8,870
  • Joined: 03-December 12

Re: JavaScript runtime rror: Not an array

Posted 06 January 2017 - 09:54 AM

On line 17 of the html?
Was This Post Helpful? 0
  • +
  • -

#3 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 92
  • Joined: 20-May 16

Re: JavaScript runtime rror: Not an array

Posted 06 January 2017 - 11:27 AM

View Postastonecipher, on 06 January 2017 - 09:54 AM, said:

On line 17 of the html?


I am not sure what you mean.
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • Licensed PITA
  • member icon

Reputation: 2204
  • View blog
  • Posts: 8,870
  • Joined: 03-December 12

Re: JavaScript runtime rror: Not an array

Posted 06 January 2017 - 12:11 PM

What line is throwing the error????


This one, on line 17!?!?!?!?!?!?

var data = google.visualization.arrayToDataTable(r.d); 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1