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 System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public partial class MyOptimizePieChartForPorject : System.Web.UI.Page
{
//This programe is use to Create a pie chart and Dispaly the completed process in the ratio of //20%,30% and 50% completed in diffreent colore
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
Graphics Instatnce;
const int width = 450, height = 400;//Height and widht of rectangel Image in which we //draw the pie chart
Bitmap ObjBitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
Graphics ObjGraphics = Graphics.FromImage(ObjBitmap);
ObjGraphics.FillRectangle(new SolidBrush(Color.Violet), 0, 0, width, height);
Draw3DPieChart(ref ObjGraphics);
ObjBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
ObjGraphics.Dispose();
ObjBitmap.Dispose();
}
protected void Draw3DPieChart(ref Graphics objGraphics)
{
int iLoop, iLoop2;
// Create location and size of ellipse.
// int x = 50;
//int y = 20;
int x = 10;//X-axis
int y = 10;//y axis
int width = 250;//Width of Pie chart
int height = 250;//height of pie chart
// Create start and sweep angles.
int startAngle = 0;//starting point to filling the chart
int sweepAngle = 60;//defining how much we draw the angle to fill the pie chart
SolidBrush objBrush = new SolidBrush(Color.Aqua);
Random rand = new Random();
objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
objBrush.Color = Color.Red;
DrowPie(objGraphics,objBrush, 10, 10, 250, 250, 0, 20);//this fuction is user to draw and //fill the pic chart
DrowIndecatedRectangle(objGraphics,objBrush, 0);//drawing the rectangle to Indicateing wich color is showing which section
//DrawString is use to wirite any incation or words
objGraphics.DrawString("Completed 20%", new Font("Verdana", 8, FontStyle.Bold), Brushes.Red, 330, 25 + (0 * 50) + 10);
objBrush.Color = Color.Gray;
DrowPie(objGraphics,objBrush, 10, 10, 250, 250, 20, 30);
DrowIndecatedRectangle(objGraphics, objBrush, 1);
objGraphics.DrawString(" Completed 30%", new Font("Verdana", 8, FontStyle.Bold), Brushes.Gray, 330, 25 + (1 * 50) + 10);
objBrush.Color = Color.Yellow;
DrowPie(objGraphics, objBrush, 10, 10, 250, 250, 50, 50);
DrowIndecatedRectangle(objGraphics, objBrush, 2);
objGraphics.DrawString(" Completed 50%", new Font("Verdana", 8, FontStyle.Bold), Brushes.Yellow, 330, 25 + (2 * 50) + 10);
}
//This function is user to drow the pie chart
protected void DrowPie(Graphics objGraphics, SolidBrush objBrush, int x, int y, int width, int height, int startAngle, int sweepAngle)
{
//meaning of paramenters variable
//int x-- is use to declare the x-axis of pie chart
//int y -- is use to declare the y-axis
//int width use to declare the width of pie chart
//int heigh use to declare the height of pie chart
startAngle = PercentageAngle(startAngle);
sweepAngle = PercentageAngle(sweepAngle);
objGraphics.FillPie(objBrush, x, y, width, height, startAngle, sweepAngle);
}
//This function is use the Draw the rectangle to indicate the color and its use
protected void DrowIndecatedRectangle(Graphics ObjGraphics,SolidBrush objBrush,int i)
{
//int i --is use to maintain thepositnion of rectangle
ObjGraphics.FillRectangle(objBrush, 290, 25 + (i * 50), 25, 25);
}
//This function is use to change the completed percent in degree of circle like //360 degrdd==100%
protected int PercentageAngle(int input)
{
int totalAngle = (360* input / 100) ;
return totalAngle;
}
}
No comments:
Post a Comment