gpt4 book ai didi

c# - WinForm Chart - 增加滚动粒度

转载 作者:行者123 更新时间:2023-11-30 23:05:51 27 4
gpt4 key购买 nike

以我正在处理的示例为例,创建一个 WindowsForms 应用程序,创建一个新的图表,并将以下内容添加为加载事件:

this.chart1.Series.Clear();
this.chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
this.chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
this.chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
this.chart1.ChartAreas[0].CursorX.Interval = 1 / 24.0 / 60.0; // To increase selection granularity
this.chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
this.chart1.ChartAreas[0].AxisX.LabelStyle.Format = ("M/d H:mm:ss");

var series = new Series("Some Series") {ChartType = SeriesChartType.Line};
for (var i = 0; i < 5; i++)
{
series.Points.AddXY(DateTime.UtcNow.AddDays(i), i + 1);
}

this.chart1.Series.Add(series);

当我运行它时,我可以放大数据以便更仔细地观察,但是水平滚动条的行为并不是我想要的;无论系列的内部数据如何,单击任一箭头都会向任一方向跳转一整天。如果少于一天的数据,它会跳到最后。拖动栏同样受到限制。如何指定我希望此间隔的 TimeSpan,或者以其他方式启用平滑滚动?

最佳答案

这很好地隐藏在文档中。

首先我们找到 this ,指的是图表的 Axis 成员的 ScrollBar 属性。我们正在处理一个 AxisScrollBar 对象,信息在本文的“备注”部分: https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.axisscrollbar.aspx

To control the large scrolling size, use the Size property of the ScaleView object. To set the small scrolling size, use the SmallScrollSize property of the AxisScaleView class.

因此,例如,

this.chart1.ChartAreas[0].AxisX.ScaleView.Size = 50;
this.chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 5;

要使滚动大小与 View 中的时间单位相对应,请使用 AxisScaleView 对象的 SmallScrollSizeType 属性。再举一个例子,此属性的可能值记录在 here 中。

this.chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Weeks;

关于c# - WinForm Chart - 增加滚动粒度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48552883/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com