Page 1 of 1

Y-Axis labelling - how to manage the size better

Posted: Tue Oct 04, 2016 5:04 pm
by greggorob64
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

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

Posted: Wed Oct 05, 2016 7:47 am
by ArctionPasi
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";
                }
            }
            
        }


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

Posted: Wed Oct 05, 2016 12:31 pm
by greggorob64
Thanks pasi, i'll give this a try

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

Posted: Thu Oct 13, 2016 8:23 pm
by greggorob64
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