asp.net图表堆积条形图未获得所需的输出

时间:2017-01-12 05:14:11

标签: c# asp.net charts asp.net-charts

我正在创建stackbar chart for may following datatable在google搜索所有可能的解决方案并修改了我的代码但是我不知道我的逻辑是否出错这是我的数据表 My DataTable

这是我的代码:

  private void fillStackedChart()
    {
        dt = new DataTable();
      cmd = new MySqlCommand("SELECT STATUS , count( resultstatus ) AS Total_Count, clashresult.floor_srno, floor_master.floor_Name FROM clashresult INNER JOIN floor_master ON clashresult.floor_srno = floor_master.floor_srno WHERE floor_master.project_srno =2 GROUP BY STATUS , clashresult.floor_srno, floor_master.floor_Name ORDER BY floor_master.floor_Name", con);
        da = new MySqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        StackedChart.DataSource = dt;
            DataTable dt2 = new DataTable();
        MySqlDataAdapter adp = new MySqlDataAdapter("SELECT Distinct status from clashresult inner join floor_master on clashresult.floor_srno=floor_master.floor_srno where floor_master.project_srno=2 group by STATUS,clashresult.floor_srno,floor_master.floor_Name", con);
          adp.Fill(dt2);
        int amountofrows = Convert.ToInt32(dt2.Rows.Count);
        for (int i = 0; i < amountofrows; i++)
        {
            List<string> xvals = new List<string>();
            List<decimal> yvals = new List<decimal>();

            string serieName = dt2.Rows[i]["status"].ToString();
            StackedChart.Series.Add(serieName);

            StackedChart.Series[i].ChartType = SeriesChartType.StackedBar;

            //FORMATTING THE CHART
            StackedChart.Series[i].Label = dt.Rows[i]["Total_Count"].ToString();
            StackedChart.Legends.Add(new Legend(dt2.Rows[i]["status"].ToString()) { Docking = Docking.Right });
            StackedChart.Series[i].BorderWidth = 0;
            StackedChart.Series[i].BorderColor = Color.Black;
            StackedChart.Series[i]["PixelPointWidth"] = "30";
            StackedChart.Series[i].LabelForeColor = Color.White;
            StackedChart.BackColor = Color.LightSkyBlue;

            foreach (DataRow dr in dt.Rows)
            {
                try
                {
                    if (String.Equals(serieName, dr["status"].ToString(), StringComparison.Ordinal))
                    {
                        xvals.Add(dr["floor_Name"].ToString());
                        yvals.Add(Convert.ToDecimal(dr["Total_Count"].ToString()));
                    }
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Diagrammet kunde inte ritas upp");
                }
            }
            try
            {
                StackedChart.Series[serieName].XValueType = ChartValueType.String;
                StackedChart.Series[serieName].YValueType = ChartValueType.Auto;
                StackedChart.Series[serieName].Points.DataBindXY(xvals.ToArray(), yvals.ToArray());
            }
            catch (Exception)
            {
                throw new InvalidOperationException("Diagram Cannnot Be displayed!");
            }
        }
        StackedChart.DataBind();
        StackedChart.Visible = true;
    }

我正在接受这样的出局 enter image description here

但我正在寻找的输出是这样的:所有条形应该如下所示enter image description here

这只是单个堆叠条,但我想在上面的图表中相同。 请帮助我出错的地方。 提前致谢

0 个答案:

没有答案