3

我正在使用 C# 中的图表控件开发几个条形图,其中一个包含一系列 ~2300 个数据点。为了能够正确显示每个数据点的自定义标签,我将图表的高度扩展为 10000。但是,它现在为图表生成了相当大的页眉和页脚,如下所示: 图表上的巨大标题

但是,当我将图表设置为恢复正常高度 500 时,标题大小又恢复为更合理。如何手动调整标题大小?

这是我的图表属性代码:

Chart chart = new Chart();
chart.Width = 1000;
chart.Height = 10000;
chart.BackColor = Color.FromArgb(211, 223, 240);
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BackGradientStyle = GradientStyle.TopBottom;
chart.BorderlineWidth = 1;
chart.Palette = ChartColorPalette.Bright;
chart.BorderlineColor = Color.FromArgb(26, 59, 105);
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
chart.Titles.Add("Hit Rate");
chart.IsSoftShadows = true;

chart.ChartAreas.Add("Left");
chart.ChartAreas["Left"].AxisX.Title = "Market Area";
chart.ChartAreas["Left"].AxisY.Title = "Hit Percentage";

更新:我已将此添加到我的代码中...

chart.ChartAreas["Left"].InnerPlotPosition.X = 5;
chart.ChartAreas["Left"].InnerPlotPosition.Y = 0f;

这在一定程度上有所帮助。此外,我发现导致问题的不是标题本身的大小。标题的高度其实很正常。相反,它是分配给实际绘图区域上方图表的所有空白空间。

4

2 回答 2

0

让我们试试这个:

chart.Titles[0].Position.Auto = false;
chart.Titles[0].Position.Width = 60; //change the size you want

auto = false 表示您手动计算位置。我认为默认情况下标题的宽度是图表的 50% 和 50%。

卢多

于 2014-03-18T16:19:58.307 回答
0

与其手动设置图表的高度和宽度,不如让它根据内容自动设置并设置如下:

chart.ChartAreas[0].AxisX.Interval = 1;
chart.ChartAreas[0].AxisY.Interval = 1;

(这里我选择图表区域0,根据你的代码改变它)

添加上面的代码时,不要设置图表的高度和宽度。如有问题请告诉我

于 2014-03-24T07:46:19.667 回答