C#Winform图表,缩放和缩放x轴显示日期和时间

本文关键字:缩放 显示 日期 时间 图表 C#Winform | 更新日期: 2024-10-21 21:39:54

我有一个winform,里面有图表,在我的代码中我已经设置了:

//Enable range selection and zooming end user interface
        this.chart1.ChartAreas["ChartArea1"].CursorX.IsUserEnabled = true;
        this.chart1.ChartAreas["ChartArea1"].CursorY.IsUserEnabled = true;
        this.chart1.ChartAreas["ChartArea1"].CursorX.IsUserSelectionEnabled = true;
        this.chart1.ChartAreas["ChartArea1"].CursorY.IsUserSelectionEnabled = true;
        this.chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoomable = true;
        this.chart1.ChartAreas["ChartArea1"].AxisY.ScaleView.Zoomable = true;
        this.chart1.ChartAreas["ChartArea1"].AxisX.ScrollBar.IsPositionedInside = true;
        this.chart1.ChartAreas["ChartArea1"].AxisY.ScrollBar.IsPositionedInside = true;

它会根据选择进行缩放。但是,我的选择仅限于网格线。此外,在选择时,会出现一个红十字,该红十字仅停留在固定的x轴值。如何修改这样的选择不限于网格线/特定的固定x轴值?

我还将x轴类型设置为日期时间,即

this.chart1.Series[chanName].XValueType = ChartValueType.DateTime;

但是,x轴只显示日期,而不显示时间。如何在x轴上同时显示日期和时间?谢谢

C#Winform图表,缩放和缩放x轴显示日期和时间

您可以通过设置LabelStyle在x轴上显示日期和时间。格式化属性。

this.chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "g";

您需要设置CursorX。Interval属性。其默认值为1.0。

this.chart1.ChartAreas["ChartArea1"].CursorX.Interval = 1 / 24.0 / 60.0; // 1 minute

您还可以设置AxisX。缩放视图。MinSize属性以限制选择。其默认值未设置。

this.chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.MinSize = 1 / 24.0 / 60.0;