Microsoft Silverlight 图表奇数区间

发布于 2024-10-21 04:02:46 字数 314 浏览 5 评论 0原文

在 Silverlight 中的一个简单的 Microsoft 图表控件中,我将一个月中的日期作为 X 轴上的日期和 Y 轴上的双精度值。我想在 X 轴上每隔一天显示一次,但那些日子应该是奇数天

如果我设置 IntervalType="Days" 和 Interval="2",则编号始终从第 2 天开始。即使我在前面或末尾或两者都放置了一个虚拟日期。

而不是: __ 02 __ 04 __ 06 __ 08 __ 10 ...

我需要: 01 __ 03 __ 05 __ 07 ...

我怎样才能以最简单的方式实现这一目标?

In a simple Microsoft chart control in Silverlight I have the days of one month as dates on the X axis and double values on the Y axis. I would like to display every second day on the X axis but those days should be the odd days.

If I set the IntervalType="Days" and Interval="2" the numbering always starts with day 2. Even if I put a dummy date in front or in the end or both.

Instead of:
__ 02 __ 04 __ 06 __ 08 __ 10 ...

I need:
01 __ 03 __ 05 __ 07 ...

How can I achieve this in the simplest way?

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

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

发布评论

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

评论(1

メ斷腸人バ 2024-10-28 04:02:46

集合示例 31.01 -> 1.02-> 3.02 而不是 31.01 -> 2.02 。在这种情况下,唯一的方法是编写类似于 DateTimeAxis 的自定义 Axis

首先将以下文件复制到您的项目中:

  • c:\Program Files\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Source\Source code.zip\Controls.DataVisualization.Toolkit\EnumerableFunctions.cs
  • c:\Program Files \Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Source\Source code.zip\Controls.DataVisualization.Toolkit\ValueHelper.cs

使用完全相同的命名空间复制这些文件,它们是内部的,因此不会出现名称冲突。
接下来,添加 DateTimeIntervalType 的扩展类:

namespace System.Windows.Controls.DataVisualization.Charting
{
    /// <summary>
    /// A date time interval.
    /// </summary>
    public enum ExtendedDateTimeIntervalType
    {
        /// <summary>
        /// Automatically determine interval.
        /// </summary>
        Auto = 0,

        /// <summary>
        /// Interval type is milliseconds.
        /// </summary>
        Milliseconds = 1,

        /// <summary>
        /// Interval type is seconds.
        /// </summary>
        Seconds = 2,

        /// <summary>
        /// Interval type is minutes.
        /// </summary>
        Minutes = 3,

        /// <summary>
        /// Interval type is hours.
        /// </summary>
        Hours = 4,

        /// <summary>
        /// Interval type is days.
        /// </summary>
        Days = 5,

        /// <summary>
        /// Interval type is weeks.
        /// </summary>
        Weeks = 6,

        /// <summary>
        /// Interval type is months.
        /// </summary>
        Months = 7,

        /// <summary>
        /// Interval type is years.
        /// </summary>
        Years = 8,

        /// <summary>
        /// Interval type is odd days
        /// </summary>
        OddDays = 9
    }
}

为了使新成员 OddDays 工作,我更改了类 DataTimeRangeAxis这里有一个关于pastebin的链接,因为SO的程序员不注意诸如带有长解释的答案之类的小事。

将命名空间 SilverlightApplication3 更改为您想要的任何名称(System.Windows.Controls.DataVisualization.Charting 除外)。

另外,我对最后一个函数的代码进行了注释,因为它包含许多依赖项,并且我不想将额外的文件复制到应用程序。没有此代码,轴可以正常工作,可能根本没有使用此函数。

该类最重要的部分在函数 IncrementDateTime 中:

        //The interval type forced by a user, not actual interval type
        if (this.IntervalType == ExtendedDateTimeIntervalType.OddDays)
        {
            DateTime newDate;
            if(span != TimeSpan.Zero) //automatically created interval
                newDate = date.Add(span);
            else newDate = date.AddDays(interval); //else use the interval which is set by a user

            //find the nearest odd day
            while (newDate.Day % 2 != 1)
                newDate = newDate.AddDays(1);
            //update span
            span = newDate - date;
        }

Xaml 看起来是这样的:

        <charting:Chart.Axes>
            <local:DateTimeAxis IntervalType="OddDays" Orientation="X" Interval="1"/>
        </charting:Chart.Axes>

您可以设置 Interval="2" 而不是 1,但它会跳过这一天在集合 31.01-1.02-3.02 中,因此最好使用值 1。

Example for a set 31.01 -> 1.02 -> 3.02 instead of 31.01 -> 2.02. In that case the only one way is to write the custom Axis similar to the DateTimeAxis.

At first copy to your project the following files:

  • c:\Program Files\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Source\Source code.zip\Controls.DataVisualization.Toolkit\EnumerableFunctions.cs
  • c:\Program Files\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Source\Source code.zip\Controls.DataVisualization.Toolkit\ValueHelper.cs

Copy these files with exactly the same namespace, they are internal so there will not be a name conflict.
Next, add the extended class for DateTimeIntervalType:

namespace System.Windows.Controls.DataVisualization.Charting
{
    /// <summary>
    /// A date time interval.
    /// </summary>
    public enum ExtendedDateTimeIntervalType
    {
        /// <summary>
        /// Automatically determine interval.
        /// </summary>
        Auto = 0,

        /// <summary>
        /// Interval type is milliseconds.
        /// </summary>
        Milliseconds = 1,

        /// <summary>
        /// Interval type is seconds.
        /// </summary>
        Seconds = 2,

        /// <summary>
        /// Interval type is minutes.
        /// </summary>
        Minutes = 3,

        /// <summary>
        /// Interval type is hours.
        /// </summary>
        Hours = 4,

        /// <summary>
        /// Interval type is days.
        /// </summary>
        Days = 5,

        /// <summary>
        /// Interval type is weeks.
        /// </summary>
        Weeks = 6,

        /// <summary>
        /// Interval type is months.
        /// </summary>
        Months = 7,

        /// <summary>
        /// Interval type is years.
        /// </summary>
        Years = 8,

        /// <summary>
        /// Interval type is odd days
        /// </summary>
        OddDays = 9
    }
}

To make the new member OddDays work, I've changed the class DataTimeRangeAxis. Here is a link on pastebin, because programmers of SO don't pay attention to such trifle as answers with long explanation.

Change the namespace SilverlightApplication3 to whatever your want (except System.Windows.Controls.DataVisualization.Charting).

Also I've commented the code at the last function, because it contains many dependencies and I didn't want to copy extra files to the application. The axis works fine without this code, probably this function isn't used at all.

The most important part of the class is in the function IncrementDateTime:

        //The interval type forced by a user, not actual interval type
        if (this.IntervalType == ExtendedDateTimeIntervalType.OddDays)
        {
            DateTime newDate;
            if(span != TimeSpan.Zero) //automatically created interval
                newDate = date.Add(span);
            else newDate = date.AddDays(interval); //else use the interval which is set by a user

            //find the nearest odd day
            while (newDate.Day % 2 != 1)
                newDate = newDate.AddDays(1);
            //update span
            span = newDate - date;
        }

Xaml will look so:

        <charting:Chart.Axes>
            <local:DateTimeAxis IntervalType="OddDays" Orientation="X" Interval="1"/>
        </charting:Chart.Axes>

You can set Interval="2" instead of 1, but it will skip the day in the set 31.01-1.02-3.02, so it is better to use the value 1.

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