Show durations in an ASP.NET Bar Chart

浪尽此生 提交于 2019-12-23 23:18:07

问题


I have an app in which I'm using the included ASP.NET Chart controls. In one of my charts, I need to show a Bar chart with durations. The durations are stored as TimeSpan objects as shown here:

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

When I execute this, an Exception is thrown that says:

Series data points do not support values of type System.TimeSpan only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort.

The exception is very clear what the problem is. However, how do I show my durations in a bar chart then?

Thank you!


回答1:


So then instead of having your durations be of type TimeSpan, which the exception is telling you Series data points do not support, why not use the Minutes property of the timespan? 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);


来源:https://stackoverflow.com/questions/15364652/show-durations-in-an-asp-net-bar-chart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!