Jump to content
Software FX Community

Issues with legend sizing


User (Legacy)

Recommended Posts

Hello,

I am having a problem getting the legend box to size to an "appropriate"

width. What I would prefer is that long series labels are wrapped to

multiple lines when there is enough vertical space so that the PLOT area is

MAXIMIZED (e.g. minimal legend width to display all the series' labels, see

attachment)

However, the only way I can make this happen is to MANUALLY calculate the

width and set it. SizeToFit() always sets the width to the fit the LONGEST

text without wrapping, even if Flags.WordBreak is set. What I would prefer

is an automatic method, so that if the user enlarges the chart, the legend

wrapping adjusts to match.

A further difficulty is that when I call SizeToFit, the width is NOT

recalculated immediately. For example, I tried to do this:

If (Chart1.SerLegBoxObj.Flags And LegendBoxFlag.WordBreak) =

LegendBoxFlag.WordBreak Then

Chart1.SerLegBoxObj.AutoSize = False

' calculate legend width (will fit longest text):

Chart1.SerLegBoxObj.SizeToFit()

' Now we want to reduce the width to force the word wrapping (wrap

to 3 lines).

Chart1.SerLegBoxObj.Width /= 3

End If

However, if I check the width before AND after SizeToFit(), it is 22 (too

small to even see). So my width reduction does not work. But if I skip

past the If block, it DOES size-to-fit when the chart renders. I even tried

adding "Chart1.Refresh()" before checking the width, but it was STILL 22.

Can you provide some code to achieve this? Also, it would probably be a

great feature to add a "Best Fit" method to do it automatically. For the

future.

Thanks,

Greg Walker

Link to comment
Share on other sites

Unfortunately there is no functionality that will do this type of legend

resizing. Word breaks will only occur if the size is FORCE to be smaller.

Is the legend ON by the time you call SizeToFit ? If so, you should get the

correct size back.

The following code worked for me:

chart1.SerLeg[0] = "Series 1 which is very long indeed";

chart1.SerLeg[1] = "Series 2";

chart1.SerLegBoxObj.Flags |= LegendBoxFlag.WordBreak;

chart1.SerLegBoxObj.Alignment = ToolAlignment.Spread;

chart1.SerLegBox = true;

chart1.SerLegBoxObj.AutoSize = true;

chart1.SerLegBoxObj.SizeToFit();

chart1.SerLegBoxObj.Width = chart1.SerLegBoxObj.Width /= 2;

textBox3.Text = chart1.SerLegBoxObj.Width.ToString();

Notice that, once the legend is displayed, SizeToFit will not do anything

if AutoSize is set to false.

--

FP

Software FX, Inc.

post-2107-13922378307822_thumb.gif

Link to comment
Share on other sites

The legend is on; in fact my code is very similar to yours.  I think the

difference may be that I am doing the chart setup *before* the form displays

(WinForms app), so the chart is not getting any Paint messages, even when

Chart1.Refresh() is called. My guess is that the width calculation is only

being done in the Paint event (which seems logical, since that is the only

time you would have a Graphics context).

I may look at moving my legend setup until after the form renders, but for

the moment it is working -- I am manually calculating an appropriate legend

width.

Thanks anyway,

GW

"SoftwareFX Support" <support@softwarefx.com> wrote in message

news:ICDJJmUfDHA.3296@WEBSERVER1...

> Unfortunately there is no functionality that will do this type of legend

> resizing. Word breaks will only occur if the size is FORCE to be smaller.

>

> Is the legend ON by the time you call SizeToFit ? If so, you should get

the

> correct size back.

>

> The following code worked for me:

>

> chart1.SerLeg[0] = "Series 1 which is very long indeed";

> chart1.SerLeg[1] = "Series 2";

>

> chart1.SerLegBoxObj.Flags |= LegendBoxFlag.WordBreak;

>

> chart1.SerLegBoxObj.Alignment = ToolAlignment.Spread;

>

> chart1.SerLegBox = true;

>

> chart1.SerLegBoxObj.AutoSize = true;

>

> chart1.SerLegBoxObj.SizeToFit();

>

> chart1.SerLegBoxObj.Width = chart1.SerLegBoxObj.Width /= 2;

>

> textBox3.Text = chart1.SerLegBoxObj.Width.ToString();

>

> Notice that, once the legend is displayed, SizeToFit will not do anything

> if AutoSize is set to false.

>

> --

> FP

> Software FX, Inc.

>

>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...