Re: Chart Control Axis Label
I'm not sure you can have the tick marks and labels fixed without having some calculations done inbetween and changing you Axis settings. You can have a fixed number of labels, and if the time span of the chart is constant, it might not move at all... I'm not sure.
I'd suggest to at least set a fixed interval for your X Axis so that you will have constant spacing.
Here are some chart setting pointers that might be useful for you:
Code:
localChartArea.CursorX.Interval = 1;
localChartArea.CursorX.IntervalType = DateTimeIntervalType.Minutes;
localChartArea.CursorX.IsUserEnabled = true;
localChartArea.CursorX.IsUserSelectionEnabled = true;
localChartArea.CursorX.SelectionColor = Color.LightBlue;
localChartArea.AxisX.MinorGrid.Enabled = false;
localChartArea.AxisX.MajorGrid.Enabled = true;
localChartArea.AxisX.MinorTickMark.Enabled = true;
localChartArea.AxisX.LabelStyle.Format = "dd. HH:mm"; // day. 24Hour:minutes
localChartArea.AxisX.LabelStyle.Interval = 0; // Automatic
localChartArea.AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Minutes;
localChartArea.AxisX.Interval = 0; // Automatic
localChartArea.AxisX.IntervalType = DateTimeIntervalType.Hours;
localChartArea.AxisX.IntervalOffsetType = DateTimeIntervalType.Minutes;
You can change the 'Interval' values to something other than 0 and test how it works.
Take into account that MSCharts can't handle DateTime and TimeSpan variables. What they use is the OADate version of them. It's a bit confusing sometimes when you start adding and substracting dates to get your min/max scale values, so keep track of what you do.
Code:
double nowAsOADate = DateTime.Now.ToOADate();