为什么我的图表显示不正确?

时间:2016-08-03 18:00:27

标签: c# winforms charts

我创建了一个从存储过程返回数据表的函数。然后我创建了另一个函数来填充数据表中的图表,但我的图表看起来并不完整。仅显示系列名称(参见图片)。 mychart

我的数据条location_namerecount

中有两列

我的功能

public void FillChartReciversByLocations()
        {
            DataTable dt = new DataTable();
            BL.recivers rec= new BL.recivers();
            dt = rec.ReciversByLocations();
            chart1.DataSource = dt;
            chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string SeriesName = dt.Rows[i]["location_name"].ToString();
                chart1.Series.Add(SeriesName);
                chart1.Series[SeriesName].XValueMember ="location_name";
                chart1.Series[SeriesName].YValueMembers = "reccount";
            }
            chart1.DataBind();

        }

1 个答案:

答案 0 :(得分:0)

感谢所有我在尝试多次真正的代码后获得解决方案

 public void FillChartReciversByLocations()
        {
            DataTable dt = new DataTable();
            BL.recivers rec= new BL.recivers();
            dt = rec.ReciversByLocations();
            chart1.Series.Clear();
            chart1.DataSource = dt;
            string SeriesName = dt.Rows[0]["location_name"].ToString();
            chart1.Series.Add(SeriesName);
            chart1.Series[SeriesName].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
            chart1.Series[SeriesName].XValueMember = "location_name";
           chart1.Series[SeriesName].YValueMembers = "reccount";


        }