Using a "datetime" column, we have to switch things up a bit in the 
javascript, as the arrayToDataTable method doesn't support datetime 
columns.  You also have to manually parse your date format into a 
javascript compatible date format:

@using System.Data;
@using System.Collections.Generic;
@using System.Data.SqlClient;
@{    
Layout = null;

string connectionString="Server=xxx.xxx.xxx.xxx,1433\\sqlexpress; 
Database=HEK; Uid=sa; Pwd=xxxxxxxxxxxxx";
DataTable dt = new DataTable();
String rows = new String();
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT Datum, Sava, 
RPWS1 FROM vws", conn))
{
adapter.Fill(dt);



List<string> rowsList = new List<string>();
List<string> datetimeList = new List<string>;
List<string> dateList = new List<string>;
List<string> timeList = new List<string>;
foreach (DataRow row in dt.Rows)
{
// this datetime split assumes dates in the form "day.month.year 
hour:minute:second"
datetimeList = new List<string>(row["Datum"].Split(" "));
dateList = new List<string>(datetimeList[0].Split("."));
timeList = new List<string>(datetimeList[1].Split(":"));
rowsList.Add("[new Date(" + dateList[2] + ", " + dateList[1] + ", " + 
dateList[0] + ", " + timeList[0] + ", " + timeList[1] + ", " + timeList[2] 
+ "), " + row["Sava"] + ", " + row["RPWS1"] + "]");
}
rows = String.Join(", ", rowsList);
};
};
}


<script type='text/javascript' src="http://www.google.com/jsapi";></script>
<script type="text/javascript">
function drawChart() {
var data1 = google.visualization.DataTable()
data1.addColumn('datetime', 'Datum');
data1.addColumn('number', 'Savum');
data1.addColumm('number', 'RPWS1');
data1.addRows([@Html.Raw(rows)]);
 var chart = new 
google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data1, {
height: 350,
width: 900,
title: 'Absolutna kota vode v tesnilni zavesi',
vAxis: {
maxValue: 165.5,
minValue: 159,
title: 'absolutna kota'
}
});
}



On Saturday, February 23, 2013 5:35:36 AM UTC-5, Matevz Uros Pavlic wrote:
>
> Hi,
>
> i think i figured it out. I changed the data in @rows with actual rendered 
> code and it didn't work. Then i changed the Datum with Id (int) and it 
> showed graph. I guess i need to format  Datum as DateTime. Also, in the 
> heading row, there needs to be Apostrophes...
>
> How do i format Datum to DateTime? 
>
> regards, m
>
>
>

-- 
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