Reputation: 183
I want to display 2 sets of data on the same axis of a chart . On the X axis I would be displaying the UserID and on Y axis the Avg marks of all papers checked by the user. But i also want to display the number of booklets for which the avg has been derived for each user . How to go about it? I want the chart to look like this
Where The numbers besides the avgs are the number of papers checked by particular user.
Till now I have this:
private void Bindchart()
{
string msg = string.Empty;
try
{
connection.Open();
SqlCommand cmd = new SqlCommand("select Teacher_code, sum(Total_marks)/ count(*) as avgmarks , COUNT(*) as no_of_copies from " + connection.Database + "_transctn where sub_code='" + DropDown_Subjects.SelectedValue + "' and Teacher_code!='' group by Teacher_code", connection);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable ChartData = ds.Tables[0];
//storing total rows count to loop on each Record
string[] XPointMember = new string[ChartData.Rows.Count];
decimal[] YPointMember = new decimal[ChartData.Rows.Count];
int totalrows = ChartData.Rows.Count;
if (totalrows > 0)
{
for (int count = 0; count < ChartData.Rows.Count; count++)
{
//storing Values for X axis
XPointMember[count] = ChartData.Rows[count]["Teacher_code"].ToString();
//storing values for Y Axis
YPointMember[count] = Convert.ToDecimal(ChartData.Rows[count]["avgmarks"]);
}
//binding chart control
Chart1.Series[0].Points.DataBindXY(XPointMember, YPointMember);
//Setting width of line
Chart1.Series[0].BorderWidth = 5;
//setting Chart type
Chart1.Series[0].ChartType = SeriesChartType.Column;
//Chart1.Series[0].ChartType = SeriesChartType.StackedColumn;
//Hide or show chart back GridLines
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = true;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = true;
//Enabled 3D
//Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
connection.Close();
}
}
Upvotes: 1
Views: 1104
Reputation: 13188
Try this:
protected void Page_Load(object sender, EventArgs e)
{
connection.Open();
SqlCommand cmd = new SqlCommand("Your SQL here.", connection);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable ChartData = ds.Tables[0];
Chart1.Series[0].Points.DataBind(ChartData.DefaultView, "Teacher_code", "avgmarks", "");
for (int i = 0; i < Chart1.Series[0].Points.Count; i++)
Chart1.Series[0].Points[i].Label = string.Format("{0:0.00} ({1})", ChartData.Rows[i]["avgmarks"], ChartData.Rows[i]["no_of_copies"]);
connection.Close();
}
Upvotes: 1