Jump to content
Software FX Community

Legend taking precedence over chart.


Mark Johnson
 Share

Recommended Posts

When you size a chart control down really small the legend takes up all the space in the chart control.  Is there a way to have the graph take precedence over the legend?

So that when you size the control down your left with what can fit of the graph and not just show the legend?

 Thanks,

 Mark 

Link to comment
Share on other sites

You can add something like this in your code:

 this.chart1.Resize += new System.EventHandler(this.chart1_Resize);

private void chart1_Resize (object sender,EventArgs e) {  chart1.UpdateSizeNow();  if (chart1.LegendBox.Width > chart1.Width / 3) chart1.LegendBox.Width = chart1.Width / 3;  else chart1.LegendBox.AutoSize = true; }

Link to comment
Share on other sites

  • 1 month later...

I also have this problem. This works fine for controlling the chart size, but if one of the series labels doesn't fit, the entire legend disappears. Is there a way to have it display what will fit in the legend area. Ideally, if a value is too long, it would display an ellipsis at the end and the tooltop would display the entire value. Is that possible?

Link to comment
Share on other sites

We must be doing something different. I do the following code to a default chart (just dropped a new one in a form, no other code, or design-time settings):

chart1.LegendBox.Width = 120;

chart1.Series[0].Text =
"Series 1 is pretty long";

chart1.Series[1].Text =

"Series 2";chart1.Series[2].Text = "Series 3";

chart1.LegendBox.Visible =

true;

And I got the attached image

If your results are different, please attach a sample program that reproduces the problem.

Link to comment
Share on other sites

I don't think so. I created a new project and pasted your code into the form constructor without change and here is what I see. If I shorten the first one to "Series 1" then it shows up. 

I also tried docking the chart and adding a Resize event with the following line in it.

chart1.LegendBox.Width = chart1.Width / 3;

Now, if I expand it to just short of the length of the long name, it will clip the last character. Any wider shows all names. Any narrower shows like the picture I attached.

 I think I am one version back on the controls. I did add references to the project for ChartFX.WinForms which is Version 7.0.2540.35369 and ChartFX.WinForms.Base which is Version 7.0.2540.35252.

Posted Image

Link to comment
Share on other sites

Yes, that seems to have fixed it. Thanks!!!

If anyone else is interested, the code you provided works fine if the chart is fairly static. However, my users have the ability to add/remove series to/from the chart dynamically and since the chart isn't resized at that point, I still had a problem. So, whenever the series are changed I call the resize code as well. However, the UpdateSizeNow() method doesn't update the legend with AutoSize set to false, so I had to set it to true again first or it was only right every other time and there were painting problems.

Also, is there a way I can add a tooltip to the legend item with the full value? I can only find tooltips that apply to the chart itself.

Link to comment
Share on other sites

Oops, I meant on the left side. I have a gantt chart with a fixed size legend on the right with the series labels in it and data labels on the left for each row that come from a fieldmap of usage type label created on the fly by user selections from a list. Sometimes the data values can be really long and make the chart disappear. Can I restrict the size of what is shown without changing the actual data value? Or, can I force the chart area to a minimum size?

 Thanks again for your help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...