Y-Axis labelling - how to manage the size better

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Arction_LasseP

greggorob64
Posts: 183
Joined: Tue Mar 18, 2014 2:55 pm

Y-Axis labelling - how to manage the size better

Post by greggorob64 » Tue Oct 04, 2016 5:04 pm

Hello, this is more of an advice question than anything. I have a graph that is setup as segments, (screenshot on the bottom). As you can see, the Titles for the Y axis can get way longer than they should be, and it reduces redability.

I'd liek to do one of three things:

A) Insert newlines in the title text if the title text gets longer than the height of the segment
B) Cut the text off if it gets arbitrarely longer than X pixels, where X is some constant
C) Cut the text off it gets longer than the height of the segment.

Is there any way to accomplish any of these.

Right now whats coming to my mind is an 'updatetitles' method, which is called on chartresize that will call measurestring on text, compare the width to the segment width and then modify the chart title if it seems too long.

Is there a better approach?

Thanks.

Image

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

Re: Y-Axis labelling - how to manage the size better

Post by ArctionPasi » Wed Oct 05, 2016 7:47 am

Hi Greg,

you pretty much have figured out how to do it.

You may want to try also with chart.BeforeRendering event handler, pretty much like this:

Code: Select all

 void _chart_BeforeRendering(object sender, BeforeRenderingEventArgs e)
        {
            GraphSegmentInfo gsi = _chart.ViewXY.GetGraphSegmentInfo();
            for (int seg = 0; seg < gsi.SegmentCount; seg++)
            {
                foreach (AxisY yAxis in _chart.ViewXY.GetYAxesInSegment(seg))
                {
                    if ((gsi.SegmentBottoms[seg] - gsi.SegmentTops[seg]) < _chart.MeasureText("AAAA BBBB CCCC DDDD EEEE FFFF", yAxis.Title.Font).X)
                    {

                        yAxis.Title.Text = "AAAA BBBB CCCC\nDDDD EEEE FFFF";
                    }
                    else
                        yAxis.Title.Text = "AAAA BBBB CCCC DDDD EEEE FFFF";
                }
            }
            
        }

LightningChart Support Team, PT

greggorob64
Posts: 183
Joined: Tue Mar 18, 2014 2:55 pm

Re: Y-Axis labelling - how to manage the size better

Post by greggorob64 » Wed Oct 05, 2016 12:31 pm

Thanks pasi, i'll give this a try

greggorob64
Posts: 183
Joined: Tue Mar 18, 2014 2:55 pm

Re: Y-Axis labelling - how to manage the size better

Post by greggorob64 » Thu Oct 13, 2016 8:23 pm

Solution worked great, thanks. Only small hiccup i had was whether i had segements 'enabled' or not, to get the allowable width.

Now if I can just get someone to fix all of my automatic margin issues for me :D :D

Image
Image