1

我试图在饼图顶部显示标题。

chartArea1.AxisX.Title = "Product1";                 
chartArea1.AxisX.TitleFont = new Font("Arial Bold", 15, FontStyle.Bold);    
chartArea1.AxisX.TitleAlignment = StringAlignment.Center;

我尝试通过将标题添加到图表的标题集合,然后分配给图表区域标题。但它不起作用。

我还能做些什么来在饼图顶部显示标题?

4

3 回答 3

6

像下面这样的东西应该可以工作:

Chart1.Titles.Clear()
Dim newTitle As New Title("Title Here", Docking.Top, New Font("Verdana", 12), Color.Black)
Chart1.Titles.Add(newTitle)

编辑:

为了将不同的标题应用到不同的图表区域,您需要设置 Title 的DockedToChartArea属性。例如,如果我有一个包含 2 个 ChartAreas 的图表,则可以像这样添加标题:

    Title Area1Title = new Title("Title1", Docking.Top, new Font("Verdana", 12), Color.Black);
    Title Area2Title = new Title("Title2", Docking.Top, new Font("Verdana", 12), Color.Black);
    Area1Title.DockedToChartArea = Chart1.ChartAreas[0].Name;
    Area2Title.DockedToChartArea = Chart1.ChartAreas[1].Name;
    Chart1.Titles.Add(Area1Title);
    Chart1.Titles.Add(Area2Title);
于 2012-11-12T15:39:36.327 回答
1

您应该尝试Titles.Add使用 yourChart 对象而不是 chartArea 的方法,如下所示

yourChart.Titles.Clear();   // Unnecessary if you have already clear
Title yourTitle = new Title("Title", Docking.Top, new Font("Verdana", 12), Color.Black);
yourChart.Titles.Add(yourTitle);
于 2012-11-12T17:27:50.617 回答
1

这是以完全自定义的方式添加标题的另一种方式。

Title testTitle = new Title();
testTitle.text = "Total";
testTitle.Font = new Font(FontFamily.GenericSansSerif, 14F, FontStyle.Bold);
testTitle.IsDockedInsideChartArea = true;
testTitle.Docking = Docking.Left;
testTitle.TextOrientation = TextOrientation.Rotated270;
testTitle.DockedToChartArea = TrunkChart.ChartAreas[0].Name;
TestChart.Title.Add(testTitle);

干杯

于 2013-06-25T10:40:35.907 回答