this.chart1.Series[0].Points.Clear();
this.chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
chart1.Series[0].ChartType = SeriesChartType.Pie;
this.chart1.Series["Series1"].Label = "#PERCENT{P}";
this.chart1.Series["Series1"].LegendText = "#VALX";
string sql = "select '男',cast( (select COUNT(*) from T_Answer1 where T_Answer1.性别='R1') *1.0 /(select COUNT(*) from T_Answer1) as numeric(8,2) ) union all select '女',cast( (select COUNT(*) from T_Answer1 where T_Answer1.性别='R2') *1.0/(select COUNT(*) from T_Answer1) as numeric(8,2) ) ";
DataSet ds111 = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql);
DataTable dt111 = ds111.Tables[0];
List<string> xData1 = new List<string>();
List<string> yData1 = new List<string>();
for (int i = 0; i < ds111.Tables[0].Rows.Count; i++)
{
xData1.Add(ds111.Tables[0].Rows[i][0].ToString());
yData1.Add(ds111.Tables[0].Rows[i][1].ToString());
}
chart1.Series[0].Points.DataBindXY(xData1, yData1);
看你在CSDN上也问了这个问题,最终的解决方法是显式的设置x轴的type
chart1.Series[0].XValueType = ChartValueType.String;
这样就可以了!