Friday, August 3

How to Create a Pie Chart in asp.net?

Here, i am discussing about , how to create a pie chart in asp.net

Step-1: My database Overview.


Step-2: Insert your values into your table.
Step-3: Then add a chart control to your page.

<asp:Chart ID="Chart1" runat="server">
<Series>
<asp:Series Name="Series1" ChartType="Pie">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Step-4: Then add this code behind method to your page and call this method whenever you want to load your chart.

protected void Load_Chart()
{
SqlConnection con = new SqlConnection("------- Your connection string--------“);
SqlCommand com;
com = new SqlCommand("select ProjectTitle,ProgressPercentage from Project", con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(dt);
Chart1.DataSource = dt;
Chart1.DataBind();
Chart1.Series[0].XValueMember = "ProjectTitle";
Chart1.Series[0].YValueMembers = "ProgressPercentage";
Chart1.Series[0].ToolTip = "Completed : " + "#PERCENT";//--Used to show tooltip
Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
}
Step-5: The final output:
Here is My Output with ToolTips:

Thanks Shibashish Mohanty

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

ShibashishMnty
shibashish mohanty