You have to parse the contents of the data structure returned by your query 
and output the data into a format the Visualization API can understand.  If 
you have the C# DataTable populated correctly, then you should be able to 
use something like this to output it in the correct format:

@{
    // query database and populate DataTable dt first

    // create an array of rows
    List<string> rows = new List<string>();
    rowsList.Add("['nivo Sava', 'RPWS1', 'RPWS2', 'RPWS3']");
    foreach(DataRow row in dt.rows) {
        rowsList.Add("[" + row.item["Datum"] + ", " + row.item["Sava"] + ", 
" + row.item["RPWS1"] + ", " + row.item["RPWS2"] + ", " + row.item["RPWS3"] 
+ "]");
    }
    String rows = String.Join(", ", rowsList);
}
<script type='text/javascript' src="http://www.google.com/jsapi";></script>

<script type="text/javascript>
function drawChart () {
    var data = google.visualization.arrayToDataTable([@rowsList]);
    var chart = new 
google.visualization.LineChart(document.getElementById('chart_div');
    chart.draw(data, {
        height: 350,
        width: 900,
        title: 'Absolutna kota vode v tesnilni zavesi',
        vAxis: {
            maxValue: 165.5,
            minValue: 159,
            title: 'absolutna kota'
        }
    });
}

google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
</script>

On Tuesday, February 19, 2013 6:05:06 PM UTC-5, Matevz Uros Pavlic wrote:
>
> Hi again, 
>
> these were missing :
>
> @using System.Data;
> @using System.Collections.Generic;
> @using System.Data.SqlClient;
>
> But it still doesn't work. 
>
> I (think) I managed to copy SQL table to DataTable of c# by :
>
> @using System.Data;
> @using System.Collections.Generic;
> @using System.Data.SqlClient;
> @{
>     
>     Layout = null;
>
>
>     string connectionString="Server=xxx.xxx.xxx.xxx; Database=HEK; Uid=sa; 
> Pwd=xxxxx";
>     
>     DataTable dt = new DataTable();
>     
>     using (SqlConnection conn = new SqlConnection(connectionString))
>     {
>         conn.Open();
>         using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT Sava, 
> rpws1 FROM VWS WHERE ID > 2200", conn))
>         {
>             adapter.Fill(dt);
>         };
>     };
>     
>
> Now i'd have to pass it to  Google charts, to draw the plot... ?
>
> Of course this doesn't work :
>     var data = google.visualization.arrayToDataTable(@dt);
>
> Do you have any ideas on this...i am reaaaally lost here...
>
> Tnx
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to