Page 1 of 1
Logarithmic Y axis labels and title
Posted: Fri Aug 28, 2015 1:05 pm
by jrvdboom
Hi,
I have a logarithmic Y axis with values smaller than 1. I have AutoFormatLabels set to true. It looks like this:
- yaxis1.png (51.46 KiB) Viewed 25141 times
I don't want the 0.0 values. I thought AutoFormatLabels would take care of this, but it doesn't. Instead I have to change the LabelsNumberFormat. When I set "" (empty string) it uses the default double.ToString(), which is what I would like, but the labels and title are drawn over each other (it gets worse when panning):
- yaxis2.png (51.58 KiB) Viewed 25141 times
By the way, I don't have this problem when using a linear axis.
Thanks for fixing!
Joost
Re: Logarithmic Y axis labels and title
Posted: Tue Sep 01, 2015 3:29 pm
by ArctionPasi
AutoFormatLabels doesn't handle this, and it seems we can improve it in v.7, but not v.6.
Please use this workaround:
- Set yAxis.AutoFormatLabels = False.
- define event handler for yAxis.FormatValueLabel:
Code: Select all
string ExampleLogAxesXY_FormatValueLabel(AxisBase axis, double value)
{
if (value < 1)
{
string strFormat = "0.0";
double dValue = 1;
while (dValue > axis.LogZeroClamp)
{
dValue /= axis.LogBase;
if(value >= dValue)
break;
strFormat += "0";
}
return value.ToString(strFormat);
}
return value.ToString("0");
}
Expect the left margin not to adjust correctly becuase it is based on checking maximum value with constant decimal count, so you may want to set ViewXY.AxisLayout.AutoAdjustMargins = false and define margins manually with ViewXY.Margins property.
Re: Logarithmic Y axis labels and title
Posted: Wed Sep 02, 2015 6:33 am
by jrvdboom
I think you might have misunderstood me. When I set LabelsNumberFormat to string.Empty the formatting is exactly what I want it to be, so there's no need to use the event handler.
My problem is that the left margin is calculated incorrectly. Of course I can adjust the margin manually, but I expect AutoAdjustMargins to work properly, like it does when using a linear axis.
Thanks,
Joost
Re: Logarithmic Y axis labels and title
Posted: Fri Sep 04, 2015 7:46 am
by ArctionPasi
How about just setting yAxis.LogLabelsType = LogLabelsType.Log10Exponential ? Then margins adjust correctly automatically.
- LogAxisUnder1.jpg (32.1 KiB) Viewed 25092 times
Manual margins can be calculated with aid of chart.MeasureText method. Pass axis label font, and the formatted label string. Measure both Minimum and Maximum value of axis and use the one having larger width, and add a little bit space for axis title and tick marks.
Re: Logarithmic Y axis labels and title
Posted: Fri Sep 04, 2015 9:44 am
by jrvdboom
These are nice workarounds, but the fact remains that AutoMargins should work properly for ALL ScaleTypes, ALL LogLabelsTypes and ALL LabelNumberFormats.
So please fix it in a (hopefully no too distant) future version.
Thanks,
Joost