1
votes

I have been fiddling with .net charts all afternoon long, I haven't worked out the proper way to get a chart to use 100% of its available width as X-Axis get rotated for clean display.

  • Example 1:

enter image description here

  • Example 2:

enter image description here

We can see that Example 2 behaves rather normally when AxisX.LabelStyle.Angle is set to 0. In Example 1, setting that property to -45 reduces the chart's width abnormally! I would understand an offset by a few pixels to account for the largest label overflow to the left, but there's way more than that which is blank to the left.

When you output in a document several such charts with varying X label sizes, the result is simply horrid.

How can I tweak my charts to not have their width affected by the labels on the X-axis when these are rotated ?

UPDATE: this is the desired output, consider the yellow box is the zone to which the chart should be stretching to enter image description here

1
The question is, where do you want the labels go? The control is trying to layout the information you want the best it can. What do you want the control to do exactly? truncate them? reduce the font size? make them disappear? Your question is not clear in that respect.zeFrenchy
Updated which picture outlining the area that the chart should be occupyingBuZz

1 Answers

-1
votes

You can try disabling label autofit like so

// Disable X axis labels automatic fitting
Chart1.ChartAreas["Default"].AxisX.IsLabelAutoFit = false;

or you could experiment with the various autofit options, to see if you can get a result you can tolerate

// Enable X axis labels automatic fitting
Chart1.ChartAreas["Default"].AxisX.IsLabelAutoFit = true;
// Set X axis automatic fitting style
Chart1.ChartAreas["Default"].AxisX.LabelAutoFitStyle = 
LabelAutoFitStyle.DecreaseFont | LabelAutoFitStyle.IncreaseFont | LabelAutoFitStyle.WordWrap;

finally you could just truncate your labels to a maximum length before feeding them to the graph library.