Logarithmic Y axis labels and title

Found a possible bug in LightningChart? Report it here.

Moderator: Arction_LasseP

jrvdboom
Posts: 61
Joined: Thu Apr 10, 2014 1:50 pm

Logarithmic Y axis labels and title

Post by jrvdboom » Fri Aug 28, 2015 1:05 pm

Hi,

I have a logarithmic Y axis with values smaller than 1. I have AutoFormatLabels set to true. It looks like this:
yaxis1.png
yaxis1.png (51.46 KiB) Viewed 11194 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
yaxis2.png (51.58 KiB) Viewed 11194 times
By the way, I don't have this problem when using a linear axis.

Thanks for fixing!
Joost

User avatar
ArctionPasi
Posts: 1365
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Re: Logarithmic Y axis labels and title

Post by ArctionPasi » Tue Sep 01, 2015 3:29 pm

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.
LightningChart Support Team, PT

jrvdboom
Posts: 61
Joined: Thu Apr 10, 2014 1:50 pm

Re: Logarithmic Y axis labels and title

Post by jrvdboom » Wed Sep 02, 2015 6:33 am

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

User avatar
ArctionPasi
Posts: 1365
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Re: Logarithmic Y axis labels and title

Post by ArctionPasi » Fri Sep 04, 2015 7:46 am

How about just setting yAxis.LogLabelsType = LogLabelsType.Log10Exponential ? Then margins adjust correctly automatically.
LogAxisUnder1.jpg
LogAxisUnder1.jpg (32.1 KiB) Viewed 11145 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.
LightningChart Support Team, PT

jrvdboom
Posts: 61
Joined: Thu Apr 10, 2014 1:50 pm

Re: Logarithmic Y axis labels and title

Post by jrvdboom » Fri Sep 04, 2015 9:44 am

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