C # Scale chart using DataTime for X axis

using MS Charting for .NET, I'm trying to zoom in on the scale that I created.

This works fine on the Y axis (type = float) and on the X axis if type = int, but when I have DateTime values ​​on the X axis, scrolling does not behave as it should on that axis.

Vertically, everything still behaves correctly, but so far I can zoom in on the X axis, I cannot drag the sliding bar to move to where I am zoomed. However, I can click both sides and it will jump.

Does anyone know how to fix this and make it behave the same as with float values?

Thanks!

+4
source share
4 answers

Depending on your data, try CursorX.IntervalType chart area property to something other than Auto.

You may encounter a similar problem when trying to use the small scroll arrows of the scroll bar after you are zoomed in. To fix this, you can try setting the AxisX.ScaleView.SmallScrollSizeType chart area property to the same as CursorX.IntervalType .

For example, if you have a chart with data that is reported every 30 seconds, you can use the following settings:

  chart1.ChartAreas[0].CursorX.IsUserEnabled = true; chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; chart1.ChartAreas[0].CursorX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes; chart1.ChartAreas[0].CursorX.Interval = 0.5D; chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Minutes; chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 0.5D; chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true; chart1.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm:ss"; 
+8
source

I had the same problem and these settings solve it for me:

  _chart.ChartAreas[0].CursorX.IsUserEnabled = true; _chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; _chart.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Minutes; _chart.ChartAreas[0].CursorX.Interval = 1D; _chart.ChartAreas[0].AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Minutes; _chart.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 1D; _chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; _chart.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Minutes; _chart.ChartAreas[0].AxisX.ScaleView.MinSize = 1D; _chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Minutes; _chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 1D; 

Especially the last two lines did the job.

0
source

add

  chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Seconds; 
0
source

My solution was:

 chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Milliseconds; 
0
source

Source: https://habr.com/ru/post/1335371/


All Articles