C#chart1 绑定dataGridView1

            string strConn = "server=2PNT8Q4Y5OJ0DP0\\SQLEXPRESS;uid=sa;pwd=****;database=diaocha;Max Pool Size = 512;pooling=false ;";
            SqlConnection con = new SqlConnection(strConn);
            SqlDataAdapter da = new SqlDataAdapter("select * from " + comboBox1.Text, con);
            DataSet ds = new DataSet();
            da.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];



            this.chart1.DataSource = ds.Tables[0];//绑定数据



            List<string> xData = new List<string>();
            //【满意】
            List<int> yData = new List<int>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                xData.Add(ds.Tables[0].Rows[i]["标题"].ToString());


                yData.Add(Convert.ToInt32(ds.Tables[0].Rows[i]["满意"]));
            }
            chart1.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧
            chart1.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。
            chart1.Series[0].Points.DataBindXY(xData, yData);


winform代码
桂ICP备16004754号