Telerik silverlight图表X轴标签的意外日期输出

发布于 2024-12-20 04:23:16 字数 1680 浏览 4 评论 0原文

因此,我将自定义业务对象列表绑定到 Rad 图表,例如,一年的月收入概览。我为 X 轴标签设置的日期根本没有按照我设置的方式呈现。

这是我的基本代码,您可以看到获取给定年份的 monthLedger 对象列表。 monthLedger 对象具有不同的属性,但此场景的主要属性是 monthLedger.Full_datemonthLedger.Revenue_Amount

List<monthLedger> year = getYearRevenueByMonth(2011);

DataSeries ser = new DataSeries();

foreach(monthLedger month in year)
{
    ser.Add(new DataPoint 
            { 
                YValue = Convert.ToDouble(month.Revenue_Amount), 
                Label = month.Revenue_Amount.ToString("0.00###"), 
                XValue = month.Full_Date.ToOADate()
            });
}


radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
radChart1.DefaultView.ChartArea.AxisX.AutoRange = true;
radChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";
radChart1.DefaultView.ChartArea.DataSeries.Add(ser);

以下是我在 2011 年列表中获取的数据 (Full_Date || Revenue_Amount):

  • {01/01/2011 12:00:00 AM} || 0.00
  • {01/02/2011 12:00:00 上午} || 0.00
  • {01/03/2011 12:00:00 上午} || 0.00
  • {01/04/2011 12:00:00 上午} || 0.00
  • {01/05/2011 12:00:00 上午} || 0.00
  • {01/06/2011 12:00:00 上午} || 0.00
  • {01/07/2011 12:00:00 上午} || 0.00
  • {01/08/2011 12:00:00 上午} || 0.00
  • {01/09/2011 12:00:00 上午} || 0.00
  • {01/10/2011 12:00:00 上午} || 0.00
  • {01/11/2011 12:00:00 上午} || 246.50
  • {01/12/2011 12:00:00 上午} || 311.60

我期望得到的是一个包含 12 个月的漂亮图表,但最终绘制了 13 列,并且标记的日期与我转换为 OLE 自动化日期的日期完全不同。

我附上了图形结果的屏幕截图: 在此处输入图像描述

我做错了什么?

So I'm binding a list of custom business objects to a Rad chart, for this instance, an overview of monthly revenue for a year. The dates that I'm setting for the X-axis Label aren't rendered as what I've set them at all.

Here's my basic code, you can see that get a list of monthLedger objects for a given year. The monthLedger object has different properties, but the main ones for this scenario are monthLedger.Full_date and monthLedger.Revenue_Amount.

List<monthLedger> year = getYearRevenueByMonth(2011);

DataSeries ser = new DataSeries();

foreach(monthLedger month in year)
{
    ser.Add(new DataPoint 
            { 
                YValue = Convert.ToDouble(month.Revenue_Amount), 
                Label = month.Revenue_Amount.ToString("0.00###"), 
                XValue = month.Full_Date.ToOADate()
            });
}


radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
radChart1.DefaultView.ChartArea.AxisX.AutoRange = true;
radChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";
radChart1.DefaultView.ChartArea.DataSeries.Add(ser);

Here is the data that I would get in the list for 2011 (Full_Date || Revenue_Amount):

  • {01/01/2011 12:00:00 AM} || 0.00
  • {01/02/2011 12:00:00 AM} || 0.00
  • {01/03/2011 12:00:00 AM} || 0.00
  • {01/04/2011 12:00:00 AM} || 0.00
  • {01/05/2011 12:00:00 AM} || 0.00
  • {01/06/2011 12:00:00 AM} || 0.00
  • {01/07/2011 12:00:00 AM} || 0.00
  • {01/08/2011 12:00:00 AM} || 0.00
  • {01/09/2011 12:00:00 AM} || 0.00
  • {01/10/2011 12:00:00 AM} || 0.00
  • {01/11/2011 12:00:00 AM} || 246.50
  • {01/12/2011 12:00:00 AM} || 311.60

What I expect to get is a nice chart with 12 months, but 13 columns end up being graphed and the dates labeled are not at all the same as the ones I've converted to OLE Automation Date.

I've attached a screenshot of the graphic result:
enter image description here

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡水深流 2024-12-27 04:23:16

正如我从您的图像中看到的,该图表以 30 天的步长绘制了条形图。这是由 X 轴的自动范围引起的。由于图表无法定义 1 个月的准时步长(月份有不同的天数),因此 X 轴自动定义 30 天是最合适的。
设置手动范围不会对您有帮助,因此我建议您使用 XCategory 而不是 XValue:

foreach(monthLedger month in year) 
   { 
    ser.Add(new DataPoint  
            {  
                YValue = Convert.ToDouble(month.Revenue_Amount),  
                Label = month.Revenue_Amount.ToString("0.00###"),  
                XCategory = month.Full_Date
            }); 
   } 

您可以删除此 - radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
因为不再需要它了。

干杯,
叶夫根尼娅

As I can see from your Image the Chart plots the bars with Step of 30 days. This is caused by the Automatic Range of the XAxis. Since the Chart cannot define a punctual step of 1 month (the months has different number of days), the XAxis automatically defined that 30 days is the most appropriate.
Setting a manual range won't help you so I suggest that you use an XCategory instead of XValue:

foreach(monthLedger month in year) 
   { 
    ser.Add(new DataPoint  
            {  
                YValue = Convert.ToDouble(month.Revenue_Amount),  
                Label = month.Revenue_Amount.ToString("0.00###"),  
                XCategory = month.Full_Date
            }); 
   } 

You can remove this - radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
as it is not needed any more.

Cheers,
Evgenia

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文