许多系列的图表控件宽度

Chart control width with many series

我有这张图表和图例中的一些系列,这张图表正在对接填充面板。图例具有以下属性:

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;

只有几个系列的图表:

有了更多的系列但相同的间隔日期我得到了这个结果:

问题不在于数据的规模,而在于 ChartArea 本身的大小减小。- 我该如何解决这个问题?

原因在这一行:

chart1.Legends.Add(seriesName);

它所做的是添加一个完全空的 Legend,很可能 为您添加的每个 Series。它位于默认位置,即右侧。如果你得到足够的它们,它们会将 ChartArea 推回左侧..

只需删除该行,因为所有 Series 都会添加到 default Legend 中。只是默认 Legend 您的下一行样式和位置停靠在底部。

为了演示效果,您可以为每个添加一个 LegendItem

Legend l = chart1.Legends.Add(chart1.Legends.Count + ""));
l.CustomItems.Add(Color.HotPink, chart1.Legends.Count + " *");

结果:

正如您所看到的,即使是很少的额外 Legends 也会将 ChartArea 推向左侧。你的是空的,所以他们不认为是 musch 房间,但仍然..