Control Panel
Forum
Hosting Help
6 Months free Hosting (New!)
Resources
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
80177
Average new registrations per day (in last 7 days):
39
New Registration:
Open
Register Now
Home
»
Resources
»
How to draw picture in web?
ASP.NET
ADO.NET
Web Services
Remoting
Visual Studio 2005
Error Bank
Interview Questions
Tips & Tricks
XML
HTML
Jscript/Javascript
IIS
Windows
General
Submit Resource or code snippet
... and get
surprise gifts
Win Digital camera, ASP.NET Books, Free softwares!!
How to draw picture in web?
19 Apr, 2008
Author:
yansoft
Summary
this show the way to drawing picture with data from database
.NET Classes used :
void CreatePieChart( DataSet ds,String dataColumnName, String title, int width)
{
float total = 0.0F, tmp;
int iLoop;
// find the total of the numeric data
for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++)
{
tmp = Convert.ToSingle(ds.Tables[0].Rows[iLoop][dataColumnName]);
total += tmp;
}
Font fontLegend = new Font("Verdana", 10),
fontTitle = new Font("Verdana", 15, FontStyle.Bold);
// We need to create a legend and title, how big do these need to be?
// Also, we need to resize the height for the pie chart, respective
// to the height of the legend and title
const int bufferSpace = 15;
int legendHeight = fontLegend.Height * (ds.Tables[0].Rows.Count + 1) +
bufferSpace;
int titleHeight = fontTitle.Height + bufferSpace;
int height = width + legendHeight + titleHeight + bufferSpace;
int pieHeight = width;
Bitmap objBitmap = new Bitmap(width,height);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.Clear(Color.White);
// maintain a one-to-one ratio
// Create a rectange for drawing our pie
Rectangle pieRect = new Rectangle(0, titleHeight,width,pieHeight);
// Create our pie chart, start by creating an ArrayList of colors
ArrayList colors = new ArrayList();
Random rnd = new Random();
for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++)
colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255),rnd.Next(255), rnd.Next(255))));
float startsingle = 0.0F;
float sweepsingle=0.0F;
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
for(iLoop=0;iLoop
{
sweepsingle=360* Convert.ToSingle(ds.Tables[0].Rows[iLoop][dataColumnName])/total;
objGraphics.FillPie((SolidBrush)colors[iLoop], pieRect, startsingle, sweepsingle);
startsingle += sweepsingle;
objGraphics.DrawString(ds.Tables[0].Rows[iLoop]["??"].ToString() + "??", fontLegend, (SolidBrush)colors[iLoop], new Rectangle(0, pieHeight + titleHeight+(iLoop + 1) * bufferSpace, 150, 40), format);
}
// Create the title, centered
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
objGraphics.DrawString(title, fontTitle,new SolidBrush(Color.Red),
new Rectangle(0, 0, width, titleHeight), stringFormat);
// Since we are outputting a Jpeg, set the
// ContentType appropriately
Response.ContentType = "image/jpeg";
// Save the image to the OutputStream
objBitmap.Save(Response.OutputStream,
ImageFormat.Jpeg);
}
Feedbacks about this page from members:
- No Feedbacks yet !! -
Submit Feedback
View All Feedbacks
Partners
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies.
All Rights Reserved.