Resources » Code Snippets » ASP.NET WebForms

Draw Pie Chart In Asp.Net

Updated: Category: ASP.NET WebForms
Author: Member Level: GoldPoints: 8

Draw Pie Chart In Asp.Net

How To Draw Simple Pie Chart In Asp.Net

1.Find Attached WebChart.dll
Default2.aspx Page

[%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %]

[%@ Register Assembly="WebChart" Namespace="WebChart" TagPrefix="Web" %]
[!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""]
[html xmlns=""]
[head runat="server"]
[title]Untitled Page[/title]

[form id="form1" runat="server"]
[Web:ChartControl ID="ChartControl1" runat="server" BorderStyle="Outset" BorderWidth="5px"
Height="400" Width="350" GridLines="none" Legend-Position="Bottom"]

Default2.aspx.cs Page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebChart;
public partial class Default2 : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
void CreateChart()
PieChart chart = new PieChart();
chart.DataSource = GetDataSet().Tables[0].DefaultView;
chart.DataXValueField = "Title";
chart.DataYValueField = "Price";
chart.DataLabels.Visible = true;
chart.DataLabels.ForeColor = System.Drawing.Color.Blue;
chart.Shadow.Visible = true;
chart.Explosion = 10;

DataSet GetDataSet()
DataSet ds = new DataSet();
DataTable table = ds.Tables.Add("My Table");
table.Columns.Add(new DataColumn("Title"));
table.Columns.Add(new DataColumn("Price", typeof(int)));

Random rnd = new Random();
for (int i = 0; i < 10; i++)
DataRow row = table.NewRow();
row["Title"] = "Title:" + i.ToString();
row["Price"] = rnd.Next(1, 100);
return ds;

Did you like this resource? Share it with your friends and show your love!

Responses to "Draw Pie Chart In Asp.Net"

No responses found. Be the first to respond...


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
      Last 7 Daysmore...

      Awards & Gifts
      Talk to Webmaster Tony John

      Online Members

      Rajkumar P
      Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India