如何更改图表控件的标题

时间:2014-02-19 13:45:23

标签: c#

我想更改我的Chart Control标题:

    Title title = chart1.Titles.Add("Test");
    Series s = new Series();
    s.Color = Color.Blue;
    s.ChartType = SeriesChartType.Line;
    s.BorderWidth = 3;

    s.Points.Add(new DataPoint(0.8, 3.2));
    s.Points.Add(new DataPoint(0.83, 6.5));
    s.Points.Add(new DataPoint(0.9, 12.9));
    s.Points.Add(new DataPoint(1, 25.8));
    s.Points.Add(new DataPoint(1.1, 29));
    s.Points.Add(new DataPoint(1.2, 54.8));
    s.Points.Add(new DataPoint(1.4, 58.1));

    chart1.Series.Add(s);
    chart1.Series.Add(s);

    chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.White;
    chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White;
    chart1.ChartAreas[0].AxisX.Maximum = 4;
    chart1.ChartAreas[0].AxisX.Interval = 1;
    chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
    chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number;

目前我要更改的标题是Series1 我已尝试Title title = chart1.Titles.Add("Test"),但Series1标题仍然存在。

enter image description here

编辑:

后:

s.Legend = "DifferentLegend";
chart1.Series.Add(s);

结果如下:

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要设置系列的“图例”属性,如下所示:

chart1.Series.Add(s);
chart1.Legends.Add(new Legend("DifferentLegend"));
chart1.Legends["DifferentLegend"].DockToChartArea = "Default";
chart1.Series["Series1"].Legend = "DifferentLegend";
chart1.Series["Series1"].IsVisibleInLegend = true;

标题是不同的 - 这就是图表顶部显示的内容。

此图表中还必须包含您未显示的代码,因为我无法在代码中的任何位置看到“流量费率”!

有关设置图例的详细信息,请参阅文档here

相关问题