Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

c# - Remove white and unnecessary space from Chart control

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...