簡體   English   中英

C#Winform圖表,縮放和縮放x軸顯示日期和時間

[英]C# Winform charts, zooming and scale of x axis displaying date and time

我有一個帶有圖表的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軸上顯示日期和時間? 謝謝!

您可以通過設置LabelStyle.Format屬性在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.ScaleView.MinSize屬性以限制選擇。 其默認值未設置。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM