Re: get array or datatable from codebehind to google line chart javascript

696 views
Skip to first unread message

asgallant

unread,
Nov 11, 2012, 3:50:57 PM11/11/12
to google-visua...@googlegroups.com
You need to convert the array into a DataTable object.  I don't know what the ASP DataTable looks like, so I can't help with that, but if you post the javascript rendered by the server (open the page in a browser and view the source), then I can see what steps you will have to take to make it into a Visualization API DataTable.

On Sunday, November 11, 2012 2:34:22 PM UTC-5, Pradeep Bhat wrote:

So I'm trying to use this javascript with my asp.net website https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart

I have an array in codebehind that has my data which i converted to a multidimensional datatable like this.

<in codebehind vb>
Public Property datat As DataTable

For outerIndex As Integer = 0 To 2
    Dim newRow As DataRow = table.NewRow()
    For innerIndex As Integer = 0 To 2


            newRow(innerIndex) = Array(outerIndex, innerIndex)
    Next
    table.Rows.Add(newRow)
Next

datat = table

<in asp>

function drawChart() {
    var data = <%=datat%>


I always get an error datatable not defined.

Pradeep Bhat

unread,
Nov 12, 2012, 11:26:39 AM11/12/12
to google-visua...@googlegroups.com
I'm confused the above code I have is converting it into a datatable.

asgallant

unread,
Nov 12, 2012, 1:24:09 PM11/12/12
to google-visua...@googlegroups.com
I need to see what the javascript looks like to the browser in order to help you.

Pradeep Bhat

unread,
Nov 12, 2012, 1:48:48 PM11/12/12
to google-visua...@googlegroups.com
how do i do that what I have in the code is this exactly

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", {packages:["corechart"]});
        google.setOnLoadCallback(drawcharts);
        function drawcharts(){
            var data = google.visualization.arrayToDataTable([
          [<%=mwtimepublic%>, <%=mwarraypublic%>]
            ]);
      
            var options = {
                title: 'MW Trend'
            };

            var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
            chart.draw(data, options);
        }
    </script>

asgallant

unread,
Nov 12, 2012, 3:13:17 PM11/12/12
to google-visua...@googlegroups.com
Open the page in a browser and view the page source, then paste the javascript here.

Pradeep Bhat

unread,
Nov 13, 2012, 1:15:39 PM11/13/12
to google-visua...@googlegroups.com

asgallant

unread,
Nov 13, 2012, 3:05:19 PM11/13/12
to google-visua...@googlegroups.com
Unfortunately, that doesn't help - I can't replicate the rendered javascript with your ASP code.  I need to see it the same way that the browser sees it.
Reply all
Reply to author
Forward
0 new messages