简体   繁体   English

缩放和选择不适用于具有Time类型的x轴的C#图表

[英]Zooming & selection not working for C# chart with x-axis of the type Time

I'm using the following code to allow my parts of chart to be selected and zoomed: 我正在使用以下代码来允许选择和缩放我的图表部分:

chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;

chart1.ChartAreas[0].CursorY.IsUserEnabled = true;
chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true;

It works for a chart with both x and y axes of the type Integer. 它适用于具有Integer类型的x轴和y轴的图表。

在此输入图像描述

But when I set the series value type to series1.XValueType = ChartValueType.Time; 但是当我将系列值类型设置为series1.XValueType = ChartValueType.Time; , I won't be able to zoom in the x-axis. ,我将无法放大x轴。

在此输入图像描述

When I set both axes value types for auto and add points using, for example, chart1.Series[0].Points.AddXY(DateTime.Now.ToLongTimeString(), rand.Next(10, 20)); 当我为auto设置两个轴值类型并添加点时,例如,使用chart1.Series[0].Points.AddXY(DateTime.Now.ToLongTimeString(), rand.Next(10, 20)); , then the zoom works. ,然后缩放工作。

How can I have my x-axis to be a Time and still be able to zoom? 如何让我的x轴成为时间并仍然可以缩放?

You need to set the Interval on the Cursor by default it is 1.0, I had the problem with percentages so I set my interval to 0.01 eg 1% as shown below. 您需要在光标上设置间隔默认值为1.0,我有百分比问题,所以我将间隔设置为0.01,例如1%,如下所示。 You want want to set IntervalType on the Cursor as this accepts datetime types. 您希望在Cursor上设置IntervalType,因为它接受datetime类型。

chart1.ChartAreas[0].CursorX.Interval = 0.01

More info at http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.cursor.interval%28v=vs.100%29.aspx 更多信息,请访问http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.cursor.interval%28v=vs.100%29.aspx

Your zoom most likely does not work because your test time values are all too close to each other. 您的缩放很可能不起作用,因为您的测试时间值彼此太接近了。 The zoom must be able to pick a start and end point from the user selection. 缩放必须能够从用户选择中选择起点和终点。 If start == end, a reasonable behaviour for the scale view is to do nothing. 如果start == end,则缩放视图的合理行为是什么都不做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM