wxy新人小白
2019-09-27 18:36
采纳率: 83.3%
浏览 347

索引超范围,加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条回答 默认 最新

  • threenewbee 2019-09-27 19:02
    最佳回答

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题