Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改图表控件的标题_C# - Fatal编程技术网

C# 如何更改图表控件的标题

C# 如何更改图表控件的标题,c#,C#,我想更改我的图表控件标题: 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 DataPoin

我想更改我的
图表控件
标题:

    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
Title仍然存在

编辑:

之后:

s.Legend = "DifferentLegend";
chart1.Series.Add(s);
结果是:


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

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;
标题有所不同——这是图表顶部显示的内容

还必须有这个图表的代码,你没有显示,因为我看不到'交通率'被设置在你的代码任何地方


有关设置图例的更多信息,请参阅文档。

@user3271698:尝试上述更新版本。如果您按照链接进行操作,所有内容都在文档中。祝你好运。现在表变小了,只在右半边,仍然存在系列1。我认为你的其他代码中可能存在影响此代码的问题-我建议你尝试使用调试器-逐步进行,看看发生了什么。链接中的MS文档也相当全面。除了我提供的代码外,我的代码没有触及表,顺便说一句,你的上一个代码只是将表设置为disapear