I am creating stackedbar chart for may following datatable did search over google for all possible solutions and modified my code but i dont know if my logic is going wrong this is my datatable
and this is my Code:
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;
}
and I am getting the out put like this
but the output i am looking for is like this: all bars should look like the following bars
This is just single stacked bar but i want the same in above chart. Please help where i am going wrong. Thanks in advance