索引超范围,加add出现多个标题如何解决

chart3.Titles[0].Text = "材料特性退化曲线-环氧密封胶";这句话显示索引超范围,改成chart3.Titles.Add("材料特性退化曲线-环氧密封胶");查询一次,标题就多出一次,如何改
程序如下

public void Creatchart13(string wax)
{
chart3.Series.Clear();
            //chart3.Visible = false;
            if (flag7 == true)
            {
                chart3.Visible = true;
            }
            string dbPath = @"D:\历年高考分数.db";
            string sq = @"Data Source=" + dbPath;
            m = new SQLiteConnection(sq);
            m.Open();
            SQLiteDataAdapter mAdapter = new SQLiteDataAdapter("select " + wax + ",yxlc from 表2", m);
            DataSet ds = new DataSet();
            mAdapter.Fill(ds);
            //mAdapter1.Fill(ds);
            DataTable dt = ds.Tables[0];
            //设置图表的数据源
            Series Series1 = new Series();
            chart3.DataSource = dt;
            Series1.IsValueShownAsLabel = false;//是否显示图例
            chart3.Series.Add(Series1);
            chart3.Series["Series1"].ChartType = SeriesChartType.Spline;//形状
            //chart1.Series[0].ChartType = SeriesChartType.Spline;
            chart3.Series[0].XValueMember = "yxlc";//X轴数据成员列
            //chart1.Series[0].YValueMembers = "id";//Y轴数据成员列
            chart3.Series[0].YValueMembers = wax;
            chart3.Series[0].IsValueShownAsLabel = true;//显示坐标
            chart3.ChartAreas[0].AxisX.Title = "运行里程(万公里)";
            chart3.ChartAreas[0].AxisY.Title = "故障率(%)";
            chart3.Titles[0].Text = "材料特性退化曲线-环氧密封胶";
            //chart1.Titles.Add("传感器故障发生率");
            //chart1.Width = 260;
            //chart1.Height = 260;
            chart3.Series[0].MarkerStyle = MarkerStyle.Circle;
            //需要提示的信息    
            //chart1.Series[0].ToolTip = "当前故障率:#VAL\n最高:#MAX\n最低:#Min\n";
            chart3.Series[0].ToolTip = "运行里程:#VALX\\n故障率:#VALY";
            //将文字移到外侧
            chart3.Series[0]["PieLabelStyle"] = "Outside";
            //chart1.Series[0].CustomProperties.EmptyPointValue = Average;
            chart3.Series[0].CustomProperties = "EmptyPointValue = Average";
            chart3.DataBind();
            chart3.BringToFront();
            m.Close();
                        }

1个回答

if (chart3.Titles.Count < 1)
chart3.Titles.Add("材料特性退化曲线-环氧密封胶");
else
chart3.Titles[0].Text = "材料特性退化曲线-环氧密封胶";

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问