Warm tip: This article is reproduced from stackoverflow.com, please click
c# charts whitespace winforms

Remove white and unnecessary space from Chart control

发布于 2020-10-24 05:18:02

I have a chart and I've added it to a panel but as you can see in the picture, the chart does not fill the whole panel. it has a lot of white space that I highlighted in red.

How can I remove this space on the left, right and bottom of my chart so that it fills the panel?

I tried docking it and I also changed its margin property to false but these solutions did not work.

My chart is .NET WinForms chart:

My chart is .NET WinForms chart

Questioner
Arian B
Viewed
1
TaW 2015-10-04 03:18

You can manually set the ChartArea's ElementPosition like this:

ChartArea CA = chart1.ChartAreas[0];
CA.Position = new ElementPosition(0, 0, 100, 100);

This means: Set it to the Top Left and make it fill the chart to 100%.

The remaining white space is needed for the labels; you can tweak it further still by using numbers less than 0% and/or greater than 100%.

Do note that they are not pixels but percent, so they will always relate to the whole ClientSize of the chart control!

Before and after:

enter image description hereenter image description here