2013-12-18 278 views
1

我有在它的图表一个WinForm,在我的代码我已经设置:C#WinForm的图表,缩放和x轴的刻度显示日期和时间

//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轴上显示日期和时间?谢谢!

回答

4

您可以通过设置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;