Hello
When ScaleType is set to Logarithmic, the axis labels are automatically calculated based on LogBase setting of the axis. LogBase = 10 results in 1, 10, 100, 1000 etc. Currently this behaviour cannot be disabled.
If you want to show more ticks, you can use CustomTicks. These allow you to manually set any number of ticks at any positions. Enabling CustomTicks hides the original ticks.
Code: Select all
// Adding CustomTicks
axisX.CustomTicks.Add(new CustomAxisTick(axisX, 800, "800", 10, true, Color.White, CustomTickStyle.TickAndGrid));
axisX.CustomTicks.Add(new CustomAxisTick(axisX, 900, "900", 10, true, Color.White, CustomTickStyle.TickAndGrid));
axisX.CustomTicks.Add(new CustomAxisTick(axisX, 1000, "1000", 10, true, Color.White, CustomTickStyle.TickAndGrid));
axisX.CustomTicks.Add(new CustomAxisTick(axisX, 1100, "1100", 10, true, Color.White, CustomTickStyle.TickAndGrid));
axisX.CustomTicks.Add(new CustomAxisTick(axisX, 1200, "1200", 10, true, Color.White, CustomTickStyle.TickAndGrid));
Adding CustomTicks doesn't automatically show them. You have to set CustomTicksEnabled to true for the axis. Disabling AutoFormatLabels is also a good idea. In your case, you could check inside RangeChanged event how many original labels are visible. If only one or none, then enable CustomTicks.
Code: Select all
_chart.AfterRendering += _chart_AfterRendering;
private void _chart_AfterRendering(object sender, AfterRenderingEventArgs e)
{
_chart.AfterRendering -= _chart_AfterRendering;
_chart.ViewXY.XAxes[0].RangeChanged += AxisX_RangeChanged;
}
private void AxisX_RangeChanged(object sender, RangeChangedEventArgs e)
{
double ticks = _chart.ViewXY.XAxes[0].GetMajorTicks().Length;
_chart.BeginUpdate();
if (ticks < 2)
{
_chart.ViewXY.XAxes[0].AutoFormatLabels = false;
_chart.ViewXY.XAxes[0].CustomTicksEnabled = true;
}
else if (_chart.ViewXY.XAxes[0].CustomTicksEnabled)
{
_chart.ViewXY.XAxes[0].AutoFormatLabels = true;
_chart.ViewXY.XAxes[0].CustomTicksEnabled = false;
}
_chart.EndUpdate();
}
GetMajorTicks only returns the number of original ticks while ignoring CustomTicks.
Note that we use AfterRendering event above, because RangeChanged is actually triggered when the axis is created. Since the axis or the chart itself might not be rendered yet at this point, a crash could occur.
Hope this is helpful.
Best regards,
Lasse