I have 2 columns ID and Severity, both of datatype string in my database table with the Severity column having High, Medium and Low values. I added a Chart control and specified its data using a sql data source but I'm unable to get the output as Y coordinate values should be of integer type. I need to generate a chart like below with every severity level having a percentage value:
Code:
private void GetChartData()
{
string cs = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT ID, Severity FROM AMD", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
}
Chart1.Series[0].XValueMember = "Severity";
Chart1.Series[0].YValueMembers = "ID";
Chart1.Series[0].ChartArea = "ChartArea1";
Chart1.DataSource = dt;
Chart1.DataBind();
int high = 0, med = 0, low = 0;
string[] x = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
//y[i] = dt.Rows[i][1].ToString();
if (dt.Rows[i][1].ToString().ToLower().Contains("high"))
{
high++;
}
else if (dt.Rows[i][1].ToString().ToLower().Contains("medium"))
{
med++;
}
else if (dt.Rows[i][1].ToString().ToLower().Contains("low"))
{
low++;
}
Chart1.Series[1].Points.DataBindXY(x, high);
}
}
How do I go about achieving this? Please guide... Thanks in advance...