C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




To Create a Graph in Asp.net


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: Graphics
Author: Ashok KandasamyMember Level: Diamond    
Rating: Points: 10



using System;
using System.Data;
using System.Configuration;
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.Collections;
using System.Drawing;
using System.Drawing.Imaging;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

//objBitmap.Save("Ashok.bmp");
//try { sngValue1 = Convert.ToSingle(Request["v1"]); }
//catch { sngValue1 = 0; }

//try { sngValue2 = Convert.ToSingle(Request["v2"]); }
//catch { sngValue2 = 0; }

//try { sngValue3 = Convert.ToSingle(Request["v3"]); }
//catch { sngValue3 = 0; }

}
protected void Button1_Click(object sender, EventArgs e)
{
Bitmap objBitmap = new Bitmap(200, 200);

Graphics objGraphic = Graphics.FromImage(objBitmap);

SolidBrush redBrush = new SolidBrush(Color.Red);
SolidBrush blueBrush = new SolidBrush(Color.Blue);
SolidBrush greenBrush = new SolidBrush(Color.Green);
SolidBrush whiteBrush = new SolidBrush(Color.White);
SolidBrush pinkBursh = new SolidBrush(Color.Pink);
Pen blackPen = new Pen(Color.Black, 2);

objGraphic.FillRectangle(pinkBursh, 0, 0, 200, 200);

objGraphic.DrawLine(blackPen, new Point(0, 195), new Point(195, 195));
objGraphic.DrawLine(blackPen, new Point(5, 5), new Point(5, 200));

Single sngHighestValue, sngHeight1, sngHeight2, sngHeight3;
Single sngValue1, sngValue2, sngValue3;

//sngValue1 = Convert.ToSingle(Request["v1"]);
//sngValue2 = Convert.ToSingle(Request["v2"]);
//sngValue3 = Convert.ToSingle(Request["v3"]);

sngValue1 = Convert.ToSingle(TextBox1.Text);
sngValue2 = Convert.ToSingle(TextBox2.Text);
sngValue3 = Convert.ToSingle(TextBox3.Text);

if (sngValue1 > sngValue2)
sngHighestValue = sngValue1;
else
sngHighestValue = sngValue2;

if (sngValue3 > sngHighestValue)
sngHighestValue = sngValue3;

if (sngHighestValue == 0)
sngHighestValue = 1;

sngHeight1 = (sngValue1 / sngHighestValue) * 190;
sngHeight2 = (sngValue2 / sngHighestValue) * 190;
sngHeight3 = (sngValue3 / sngHighestValue) * 190;

objGraphic.FillRectangle(redBrush, 10, 194 - sngHeight1, 50, sngHeight1);
objGraphic.FillRectangle(blueBrush, 70, 194 - sngHeight2, 50, sngHeight2);
objGraphic.FillRectangle(greenBrush, 130, 194 - sngHeight3, 50, sngHeight3);

Response.ContentType = "image/gif";

objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
}




Responses

Author: Bharathi    21 May 2008Member Level: Diamond   Points : 2
Thanks for the Code.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to display the form in Pentagonal shape
Previous Resource: Shuffle Images in DataList using Java Script
Return to Discussion Resource Index
Post New Resource
Category: Graphics


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use