Draw Pie Chart In Asp.Net


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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]
[html xmlns="http://www.w3.org/1999/xhtml"]
[head runat="server"]
[title]Untitled Page[/title]

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



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)
{
CreateChart();
}
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.DataBind();
chart.Explosion = 10;
ChartControl1.Charts.Add(chart);
ChartControl1.RedrawChart();
}

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);
table.Rows.Add(row);
}
return ds;
}
}


Attachments

  • webchart (37387-1627-WebChart.rar)
  • Comments

    No responses found. Be the first to 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:
    Email: