在ASP.NET条形图中显示持续时间 [英] Show durations in an ASP.NET Bar Chart

查看:129
本文介绍了在ASP.NET条形图中显示持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中我使用包括的ASP.NET图表控件。在我的一个图表中,我需要显示一个带有持续时间的条形图。持续时间被存储为TimeSpan对象,如下所示:

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

当我执行这个时,抛出一个异常,说:
点不支持类型System.TimeSpan的值,只能使用这些类型的值:Double,Decimal,Single,int,long,uint,ulong,String,DateTime,short,ushort。

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?

谢谢!

推荐答案

所以,而不是让你的持续时间类型TimeSpan,异常告诉你系列数据点不支持,为什么不使用时间间隔的Minutes属性? http://msdn.microsoft.com/en-us/library /system.timespan.minutes.aspx

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

这篇关于在ASP.NET条形图中显示持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆