asp.net
asp.net draw graphs first define Drawclass class
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.Drawing.Drawing2D;
Using System.Drawing.Imaging;
Using System.Drawing;
Using System.IO;
/**////<summary>
Summary description of Drawclass
</summary>
public class Drawclass
... {
Public Drawclass ()
... {
//
TODO: Add constructor logic here
//
}
Public MemoryStream Draw (DataSet ds, int tnum)
... {
Get the number of records
int count = ds. Tables[0]. Rows.Count;
Count Chart width
int WD = + * (count-1);
Set minimum width of 800
if (WD <) WD = 800;
Generating bitmap pairs of image
Bitmap img = new Bitmap (WD, 400);
Generate a drawing pair like
Graphics g = Graphics.fromimage (IMG);
Define a black brush
Pen Bp = new Pen (color.black);
Define a red brush
Pen Rp = new Pen (color.red);
Define silver-gray brushes
Pen Sp = new Pen (color.silver);
Define font for large headings
Font bfont = new Font ("Arial", fontstyle.bold);
Defining generic Fonts
Font font = new Font ("Arial", 6);
Define a larger font
Font Tfont = new Font ("Arial", 9);
Draw an undertone
G.drawrectangle (New Pen (Color.White,), 0, 0, IMG. Width, IMG. Height);
Define a black gradient brush
LinearGradientBrush brush = new LinearGradientBrush (new Rectangle (0, 0, IMG). Width, IMG. Height), Color.Black, Color.Black, 1.2F, true);
Define a blue gradient brush
LinearGradientBrush Bluebrush = new LinearGradientBrush (new Rectangle (0, 0, IMG). Width, IMG. Height), Color.Blue, Color.Blue, 1.2F, true);
Draw large headings
g.DrawString (ds. Tables[0]. rows[0]["Sendid"]. ToString () + "Order Send status Graph", Bfont, Brush, 40, 5);
Get Current Send Quantity
int nums = 0;
for (int i = 0; i < count; i++)
... {
Nums + = Convert.ToInt32 (ds. Tables[0]. rows[i]["Sendmum"]);
}
Draw Information Bulletin
string info = "Order sent time:" + ds. Tables[0]. rows[0]["Sendtime"]. ToString () + "graph generation Time:" + DateTime.Now.ToString () + "Order Total:" + tnum.tostring () + "current Total Sent:" + nums. ToString ();
g.DrawString (info, Tfont, Bluebrush, 40, 25);
Draw a picture border
G.drawrectangle (Bp, 0, 0, img.) Width-1, IMG. HEIGHT-1);
Draw vertical Coordinate lines
for (int i = 0; i < count; i++)
... {
G.drawline (Sp, + * I, p, + * I, 360);
}
Draw a timeline coordinate label
for (int i = 0; i < count; i + + 2)
... {
String st = Convert.todatetime (ds. Tables[0]. rows[i]["Sendtime"]). ToString ("hh:mm");
g.DrawString (St, font, brush, + * I, 370);
}
Draw the horizontal line
for (int i = 0; i < i++)
... {
G.drawline (Sp, + * I, + * (count-1), + * i);
int s = 2500-50 * I * 5;
Draw send axis coordinates label
g.DrawString (s.tostring (), font, brush, ten, + * i);
}
//Draw Vertical Axis
G.drawline (Bp, 40, 55, 40, 360);
//Draw horizontal axis
g.drawline (Bp, 360, M + * (count-1), 360);
//define curve Turning point
point[] p = new Point[count];
for (int i = 0; i < count; i++)
... {
p[i]. X = + + * I;
P[i]. Y = 360-convert.toint32 (ds. Tables[0]. rows[i]["Sendmum"])/5 * 3/5;
}
//Draw the Send curve
G. DrawLines (Rp, p);
for (int i = 0; i < count; i++)
& nbsp; ... {
//Draw the number of send record points
g.drawstring (ds. Tables[0]. rows[i]["Sendmum"]. ToString (), Font, Bluebrush, P[i]. X, P[i]. Y-10);
//Draw send record point
G.drawrectangle (Rp, P[i]. X-1, P[i]. Y-1, 2, 2);
}
//Draw Vertical coordinate title
G. DrawString ("Transmit volume", Tfont, Brush, 5, 40);
//Draw horizontal axis title
G. DrawString ("Send Time", Tfont, Brush, 385);
Save a drawn picture
MemoryStream stream = new MemoryStream ();
Img. Save (stream, imageformat.jpeg);
return stream;
}
}
Then call the output in the paging file
Drawclass dc = new Drawclass ();
OracleConnection conn = new OracleConnection (con);
String sql = "SELECT * from Atest";
oracledataadapter da = new OracleDataAdapter (SQL, conn);
DataSet ds = new DataSet ();
da. Fill (ds, "atest");
MemoryStream Ss=dc.draw (ds, 6);
Response.ContentType = "Image/jpeg";
Response.BinaryWrite (ss. ToArray ()); There is another way to
picture output to page pages
FileStream fs = new FileStream (@ "C:curve.jpg", FileMode.Open, FileAccess.Read);
byte[] MyData = new Byte[fs. Length];
int Length = Convert.ToInt32 (fs. Length);
Fs. Read (MyData, 0, Length);
Fs. Close ();
This. Response.OutputStream.Write (MyData, 0, Length);
This. Response.End ();
That's fine.