0
我目前正在創建一個使用Highcharts和ASP.NET MVC3(C#)的網站。如何使用C#中的數據表來填充DateTime對象?
我已填補C#中的數據表與MySQL數據庫的相關數據:
Properties http://imageshack.com/a/img17/1474/z2cy.png
要連接與Highcharts框架中的數據,有必要創建一個對象,它看起來像這樣的:
object[,] seriesData = { { new DateTime(year1int, month1int, day1int, hour1int, minute1int, second1int), temperatur1int }, { new DateTime(year2int, month2int, day2int, hour2int, minute2int, second2int), temperatur2int }, { new DateTime(year3int, month3int, day3int, hour3int, minute3int, second3int), temperatur3int } };
爲了測試我的代碼,從來就手動閱讀一些值:
object day1 = datatable.Rows[0]["DAY"];
object month1 = datatable.Rows[0]["MONTH"];
object year1 = datatable.Rows[0]["YEAR"];
object hour1 = datatable.Rows[0]["HOUR"];
object minute1 = datatable.Rows[0]["MINUTE"];
object second1 = datatable.Rows[0]["SECOND"];
object temperatur1 = datatable.Rows[0]["temperatur"];
int day1int = Convert.ToInt16(day1);
int month1int = Convert.ToInt16(month1);
int year1int = Convert.ToInt16(year1);
int hour1int = Convert.ToInt16(hour1);
int minute1int = Convert.ToInt16(minute1);
int second1int = Convert.ToInt16(second1);
int temperatur1int = Convert.ToInt16(temperatur1);
由於存在大於100行,因此必須創建一個循環,它正在讀取數據表中的值並將它們寫入數組。這是我的第一個C#項目,在這一點上,我不知道如何繼續並創建循環功能:(
就我所見,你使用的是規則的時間間隔,對於我的目的來說,使用不規則的時間是非常必要的,如下例所示: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/spline-irregular-time/ – user3129043