asp.net generate graphs to implement code _ practical skills

Source: Internet
Author: User
My dataset is the data read from the table Sendrec, there are id,sendid (order number), Sendtime (record time), Sendnum (unit time to send/I here is five minutes) several fields
The process is as follows:
public void Draw (Page page,dataset ds,int tnum) {}
Where page is used to pass a reference to the process of the page, so that the page is JPG directly to the client output generated graphs.
The DS is the data set that's taken out.
Tnum is just a parameter I want to use here, do not want to let this class to contact the reading process, so the total amount of the order is directly removed and passed to it.
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.HtmlControls;
Using System.Drawing.Drawing2D;
Using System.Drawing.Imaging;
Using System.Drawing;
Using System.IO;
public class Imgdraw
{
Public Imgdraw ()
{
}
public void Draw (Page page,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 (newrectangle (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]["Sendnum"]);
}
Draw Information Bulletin
String info= Order send time: +ds. Tables[0]. rows[0]["Sendtime"]. ToString () + "graph generation Time:" +datetime.now.tostring () + "total Order:" +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, 40+20 * I, p, 40+20 * 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, 60+30*i, 40+20* (count-1), 60+30*i);
int s = 2500-50 * I * 5;
Draw send axis coordinates label
g.DrawString (s.tostring (), font, brush, ten, + * i);
}
Draw a vertical axis
G.drawline (Bp, 40, 55, 40, 360);
Draw a horizontal axis
G.drawline (Bp, 360, count-1), 360);
Defining curve turning points
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]["Sendnum"])/5*3/5;
}
Draw a Send curve
G.drawlines (Rp, p);
for (int i = 0; i < count; i++)
{
To draw the amount of traffic sent to a record point
g.DrawString (ds. Tables[0]. rows[i]["Sendnum"]. 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 the horizontal axis title
g.DrawString ("Send Time", Tfont, Brush, 40, 385);
Save a drawn picture
MemoryStream stream = new MemoryStream ();
Img. Save (stream, imageformat.jpeg);
Picture output
Page. Response.Clear ();
Page. response.c;
Page. Response.BinaryWrite (stream. ToArray ());
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.