根据缩放比例更改DateTimeAxis

时间:2019-09-10 02:52:37

标签: c# winforms oxyplot

我想根据绘制的放大范围来更改刻度间隔和刻度值格式。

此代码更改呈现刻度值的主要刻度点的格式。但是,次刻度线不会出现,所需的轴更新设置也不会显示任何效果。

Q:是否需要分配其他属性以在缩放事件期间更新轴渲染?

    void xAxis_AxisChanged(object sender, AxisChangedEventArgs e)
    {
        var xAxis = sender as DateTimeAxis;

        switch (e.ChangeType)
        {
            case AxisChangeTypes.Zoom:
                double month = 1.0 * 30;
                double day15 = 1.0 * 15;
                double day = 1.0;
                double hour12 = 1.0 / 2;
                double hour = 1.0 / 24;
                double min30 = 1.0 / 24 / 2;
                double min15 = 1.0 / 24 / 4;
                double min10 = 1.0 / 24 / 6;
                double min5 = 1.0 / 24 / 12;
                double min = 1.0 / 24 / 60;
                double sec30 = 1.0 / 24 / 60 / 2;
                double sec15 = 1.0 / 24 / 60 / 4;
                double sec10 = 1.0 / 24 / 60 / 6;
                double sec5 = 1.0 / 24 / 60 / 12;
                double sec = 1.0 / 24 / 60 / 60;

                double range = xAxis.ActualMaximum - xAxis.ActualMinimum;

                if (range <= sec)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Milliseconds;      xAxis.MajorStep = 100;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Milliseconds; xAxis.MinorStep = 50;
                    xAxis.StringFormat = "HH:mm:ss";
                }
                else
                if (range <= sec5)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Seconds;      xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Seconds; xAxis.MinorStep = 0.25;
                    xAxis.StringFormat = "HH:mm:ss";
                }
                else
                if (range <= sec10)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Seconds;   xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm:ss";
                }
                else
                if (range <= sec15)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Seconds;   xAxis.MajorStep = 5;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm:ss";
                }
                else
                if (range <= sec30)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Seconds;      xAxis.MajorStep = 5;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Seconds; xAxis.MinorStep = 1;
                    xAxis.StringFormat = "HH:mm:ss";
                }
                else
                if (range <= min)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Seconds;   xAxis.MajorStep = 10;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm:ss";
                }
                else
                if (range <= min5)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Minutes;      xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Minutes; xAxis.MinorStep = 0.25;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= min10)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Minutes; xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= min15)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Minutes; xAxis.MajorStep = 5;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= min30)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Minutes; xAxis.MajorStep = 5;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= hour)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Minutes; xAxis.MajorStep = 15;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= hour12)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Hours;        xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Minutes; xAxis.MinorStep = 15;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= day)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Hours; xAxis.MajorStep = 4;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Minutes; xAxis.MinorStep = 30;
                    xAxis.StringFormat = "HH:mm";
                }
                else
                if (range <= day15)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Days; xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Hours; xAxis.MinorStep = 4;
                    xAxis.StringFormat = "MMM dd !";
                }
                else
                if (range <= month)
                {
                    xAxis.IntervalType = DateTimeIntervalType.Days; xAxis.MajorStep = 2;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Days; xAxis.MinorStep = 0.5;
                    xAxis.StringFormat = "MMM dd `";
                }
                else
                {
                    xAxis.IntervalType = DateTimeIntervalType.Days; xAxis.MajorStep = 1;
                    xAxis.MinorIntervalType = DateTimeIntervalType.Auto;
                    xAxis.StringFormat = "MMM dd";
                }

                xAxis.PlotModel.InvalidatePlot(updateData: false);

                break;
        }
    }

0 个答案:

没有答案