Doughnut/ Pie Chart Drawing with Percent value ASP .net

.ASPX File

<div>
<fieldset>
<div align="center">
<asp:Chart ID="ChartSessionalSummary" runat="server" Width="490px">
<Series>
<asp:Series Name="Series1" ChartType="Doughnut">
</asp:Series>
<asp:Series Name="Series2" ChartType="Doughnut">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisX Title="Letter Grade">
</AxisX>
<AxisY Title="No. of Student">
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</fieldset>
</div>

.ASPX.CS File

void DrawChart()
{
// Display 3D Pie Chart
//ChartSessionalSummary.Series["Series1"]["PieLabelStyle"] = "Inside";
// Set the pie labels to be drawn outside of the pie chart
ChartSessionalSummary.Series["Series1"]["PieLabelStyle"] = "Outside";
ChartSessionalSummary.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
// Display a Title
ChartSessionalSummary.Titles.Add("Term and Course wise Sessional Result Summary");
// Add Data to Display
string[] xValues = { "A+", "A", "A-", "B+", "B", "B-", "C+", "C", "D", "F" };
int[] yValues = { yValue("A+"), yValue("A"), yValue("A-"), yValue("B+"), yValue("B"), yValue("B-"), yValue("C+"), yValue("C"), yValue("D"), yValue("F") };
ChartSessionalSummary.Series["Series1"].Points.DataBindXY(xValues, yValues);
// Set the pie label as well as legend text to be displayed as percentage
// The P2 indicates a precision of 2 decimals
ChartSessionalSummary.Series["Series1"].Label = "#VALX (#PERCENT{P2})";
// Call Out The Letter "D"
ChartSessionalSummary.Series["Series1"].Points[9]["Exploded"] = "true";
// Display a Legend
ChartSessionalSummary.Legends.Add(new Legend("Alphabet"));
ChartSessionalSummary.Legends["Alphabet"].Title = "Description";
//ChartSessionalSummary.Series["Series1"].Legend = "Alphabet";
this.ChartSessionalSummary.Series["Series1"].LegendText = "#VALX";
// Set these other two properties so that you can see the connecting lines
//this.ChartSessionalSummary.Series["Series1"].BorderWidth = 1;
//this.ChartSessionalSummary.Series["Series1"].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
ChartSessionalSummary.Visible = true;
}
Int32 yValue(String str)
{
Int32 value = 0;
String SqlString = "sp_GraphSessional";
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(ConString);
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = SqlString;
cmd.Parameters.AddWithValue("@TermId", ddlTermId.Text);
cmd.Parameters.AddWithValue("@CourseId", ddlCourseId.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
int i = 0;
for (i = 0; i < dt.Rows.Count; i++)
{
try
{
if (dt.Rows[i]["LetterGrade"].ToString() == str)
{
value = Convert.ToInt32(dt.Rows[i]["TotalStudent"].ToString());
break;
}
else value = 0;
}
catch (Exception ex)
{
}
}
return value;
}

Stored Procedure and Function:

ALTER PROCEDURE [dbo].[sp_GraphSessional]
(
@TermId varchar(50),
@CourseId varchar(50)
)
----- exec sp_GraphSessional 'CSE2011DEC_2K10Y1T1','CSE2006MAYCSE1102'
AS
BEGIN
DECLARE @CenteralViva decimal(8,2)
SELECT DISTINCT COUNT(StudentId)AS TotalStudent,
dbo.GetMarksToGPA([dbo].[fn_TwoDigitAfterDecimalPoint](LabPerformance+Attendance+ Viva +
dbo.fn_ReturnCenteralViva(@TermId,@CourseId,StudentId) + Quiz + Grace),'LetterGrade') AS LetterGrade
FROM T_Term_Student_Result_Lab_Details
WHERE TermId=@TermId AND CourseId=@CourseId
GROUP BY dbo.GetMarksToGPA([dbo].[fn_TwoDigitAfterDecimalPoint](LabPerformance+Attendance+ Viva +
dbo.fn_ReturnCenteralViva(@TermId,@CourseId,StudentId) + Quiz + Grace),'LetterGrade')
END

ALTER function [dbo].[fn_ReturnCenteralViva]
(
@TermId varchar(50),
@CourseId varchar(50),
@StudentId int
)
returns decimal(8,2)
as
begin
declare @return decimal(8,2)
select @return = CenteralViva FROM T_Term_CenteralViva WHERE TermId=@TermId AND StudentId=@StudentId
return @return
end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s