Chart control width with many series
I have this diagram with some series in the legend and this diagram fills the panel. The legend has the following properties:
chart1.Legends.Add(seriesName); chart1.Legends[0].Docking = Docking.Bottom; chart1.Legends[0].TableStyle = LegendTableStyle.Wide; chart1.Legends[0].BorderColor = Color.CornflowerBlue; chart1.Legends[0].BorderDashStyle = ChartDashStyle.Dash; chart1.Legends[0].BorderWidth = 1;
Multi-Series Chart:
With even more series, but with the same interval date, I get this result:
The problem is not the scale of the data, but the reduced size of the ChartArea itself .. - How can I fix this?
source to share
The reason is on this line:
chart1.Legends.Add(seriesName);
What it does is add one completely blank Legend
, most likely for each one added Series
. It is placed in the default position, which is to the right. And if you get enough of them, then click to the ChartArea
left.
Just remove the line as everything Series
will be added in by default Legend
. It's just that by default Legend
your next line style and position docked with the bottom.
To demonstrate the effect, you can add LegendItem
to each:
Legend l = chart1.Legends.Add(chart1.Legends.Count + ""));
l.CustomItems.Add(Color.HotPink, chart1.Legends.Count + " *");
Result:
As you can see, even very little extra left Legends
click ChartArea
. Yours is empty, so they don't take it for themselves, but still ...
source to share