.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
satyapriyanayak
Subhransu Sekhar Jena
abhays
SP
DotnetUser

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sample Pie Chart Control coding

Posted By:Athira Sreejith       Posted Date: February 22, 2009    Points: 10    Category: ASP.NET Controls    URL: http://mgu.ac.in/  
 

Below is the sample code to create pie chart in asp.net

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

//using WebChart.Design;

using blong.WebControls;

/*

* Add this XML tag to the web.config file"

*







*/

namespace Ancilla

{

///



/// Summary description for chartcheck.

///


public class chartcheck : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Panel Panel1;

protected System.Web.UI.WebControls.Panel Pending;

protected System.Web.UI.WebControls.Panel Resolved;

protected System.Web.UI.WebControls.Label LblPending;

protected System.Web.UI.WebControls.Label LblResolved;

protected System.Web.UI.WebControls.Label LblPper;

protected System.Web.UI.WebControls.Label LblRper;

protected System.Web.UI.WebControls.Label LblHeading;

protected blong.WebControls.WebChart WebChart1;

private void Page_Load(object sender, System.EventArgs e)

{

float total,pper,rper;

int x=(int)Session["pending"];

int y=(int)Session["resolved"];

total = x+y;

if(x==0)

{

pper=0;

}

else

{

pper =(x/total)*100;

pper=(float)Math.Round(pper,2);

}

if(y==0)

{

rper=0;

}

else

{

rper =(y/total)*100;

rper =(float)Math.Round(rper,2);

}

LblPper.Text =string.Concat(pper.ToString(),"","%");

LblRper.Text =string.Concat(rper.ToString(),"","%");

blong.WebControls.WebChart chart =new blong.WebControls.WebChart();

chart.Type = blong.WebControls.WebChart.ChartType.Pie;

chart.ID ="Real";

if(x!=0 || y!=0)

{

chart.WebChartItems.Add(new WebChartItem("Pending",x,false));

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem("Resolved",y,false));

}

if(x==0 && y==0)

{

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

chart.WebChartItems.Add(new WebChartItem());

}

chart.BackColor=Color.Gainsboro;

chart.BorderWidth =2;

chart.BorderColor =Color.PowderBlue;

chart.BorderStyle =BorderStyle.Solid;

chart.ShowLegend = false;

chart.Diameter = blong.WebControls.WebChart.PieDiameter.Small;

chart.ExplodeOffset = 25;

chart.Rotate = 70;

chart.Thickness = blong.WebControls.WebChart.PieThickness.Medium;

string check = Session["check"].ToString();

if(check == "Lc")

{

chart.Title ="";

//chart.Title ="Log Calls Report Chart";

LblHeading.Text ="Log Calls Report Chart";

}

else

{

chart.Title ="";

//chart.Title ="Agent Calls Report Chart";

LblHeading.Text ="Agent Calls Report Chart";

}

chart.Format = blong.WebControls.WebChart.ChartFormat.Png;

this.Controls.Add(chart);

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///


private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}


     

Further Readings:

Responses
Author: Ruchi         Company URL:
Posted Date: March 07, 2009

Hi
can u suggest any good free charting tools that have no limitation N can be used like any other third party control( i.e just Drag N drop and code them).
Thanks

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend