2013-03-12 50 views
2

我有一個應用程序,其中使用了包含的ASP.NET圖表控件。在我的其中一張圖表中,我需要顯示帶有持續時間的條形圖。持續時間被存儲爲時間跨度的對象如下所示:在ASP.NET條形圖中顯示持續時間

List<TimeSpan> durations = GetDurations(); // Will be between 15 minutes and 6 hours 
List<string> labels = GetLabels(); 
... 
chart.Series["Default"].Points.DataBindXY(xValues, durations); 

當我執行此,一個異常被拋出,說:

系列數據點不支持類型System.TimeSpan僅值的值可以使用以下類型:Double,Decimal,Single,int,long, uint,ulong,String,DateTime,short,ushort。

這個例外很明顯是什麼問題。但是,如何在條形圖中顯示我的持續時間?

謝謝!

回答

1

因此,不是讓您的持續時間類型爲TimeSpan,而是例外情況告訴您Series數據點不支持,爲什麼不使用時間跨度的Minutes屬性? http://msdn.microsoft.com/en-us/library/system.timespan.minutes.aspx

List<int> durations = GetDurations(); // Change GetDurations to return a List<int> of the *minutes* of the timespan 
List<string> labels = GetLabels(); 
... 
chart.Series["Default"].Points.DataBindXY(xValues, durations);