K line chart

xiaoxiao2021-03-06  14

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Web; using System.Web.SessionState; using System.Web.ui; use system.web.ui.webcontrols; using system.web.ui.htmlcontrols;

Namespace azhou88gupiao {///

/// WebForm3's summary description.

/// public class Webform3: system.Web.ui.page {private void page_load (Object sender, system.eventargs e) {linechart c = new linechart (640, 480, page); c. Title = " K - Line Chart "; c. xorigin = 0; c. scalex = 2000; c. xdivs = 20; // Density c. yorigin = 0; c. scaley = 1000; c. YDIVS = 10; // coordinate Density c. AddValue (0, 150); c. AddValue (50, 50); c. AddValue (100, 700); c. AddValue (200, 150); c. AddValue (300, 450); c. AddValue 400, 75); c. AddValue (450, 450); c. AddValue (500, 250); c. AddValue (502, 50); c. AddValue (540, 250); c. AddValue (600, 50); c. AddValue (700, 250); c. AddValue (800, 50); c. AddValue (900, 250); c. AddValue (1000, 50); c. AddValue (1100, 250); c. addValue (1200 , 250); c. Draw ();} class linechart {public bitmap b; Public Stri Ng Title = "Data Chart in ASP.NET"; public arraylist chart (); public float xorigin = 0, yorigin = 0; public float scalex, scaley; public float xdivs = 2, ydivs = 2; private int Width, Height; private Graphics g; private Page p; struct datapoint {public float x; public float y; public bool valid;} public LineChart (int myWidth, int myHeight, Page myPage) {Width = myWidth; Height = myHeight; Scalex = mywidth; scaley = myHeight; b = new bitmap (mywidth, myheight); g = graphics. FromImage (b); p =

Mypage;} public void addvalue (int x, int y) {datapoint mypoint; mypoint. y = y; mypoint. Valid = true; chartvalues. Add (mypoint);} public void draw () {int I; Float X, Y, X0, Y0; String Mylabel; Pen Blackpen = New Pen (Color. Blue, 2); Brush BlackBrush = New Solidbrush (Color. Black); Font Axesfont = New Font ("Arial, 10) ; // First, create a picture size p. Response. Contenttype = "image / jpeg"; g. FillRectangle (New Solidbrush (color. Lightgreen), 0, 0, width, height); int chartinset = 25; int chartwidth = Width - (2 * chartinset); int ChartHeight = height - (2 * chartinset); g. DrawRectangle (New Pen (Color. Black, 1), Chartinset, Chartinset, Chartwidth, ChartHeight); // Write a picture above Content text g. DrawString (Title, New Font ("Arial", 14), BlackBrush, Width / 3, 10); // Write an X tag for (i = 0; i <= xdivs; i ) along the X coordinate {X = chartinset (i * chartwidth) / xdivs; y = chartHeight chartinset; mylabel = (XORIGIN (SCALEX * I / XDIVS)). Tostring (); g. DrawString (Mylabel, Axesfont, BlackBrush, x - 4 , y 10); g. Drawline (Blackpen, x, y 2, x, y - 2);} / for (i = 0; i <= ydivs; i ) {x = chartinset; y = chartHeight chartinset (i * chartheight / ydivs); MyLabel = (Yorigin (Scaley * I / YDIVS)). TOSTRING (); g. DrawString (Mylabel, Axesfont, BlackBrush, 5, Y - 6);

g. Drawline (Blackpen, X 2, Y, X - 2, Y);} g. RotateTransform (180); g. TranslateTransform (0, - height); g. translateTransform (- chartinset, chartinset); g. scaletransform (- 1, 1); DataPoint Prevoint = New DataPoint (); prevpoint. Valid = false; foreach (datapoint mypoint in chartvalues) {ix (prevoint. Valid == true) {x0 = chartwidth * (prevpoint. X - xorigin) / Scalex; y0 = chartHeight * (prevpoint. Y - yorigin) / scaley; x = chartwidth * (MyPoint. X - xorigin) / scalex; y = chartHeight * (MyPoint. Y - yorigin) / scaley; g. Drawline (Blackpen) , X0, Y0, X, Y); G. Fillellipse (BlackBrush, X0 - 1, Y0 - 1, 4); g. Fillellipse (BlackBrush, X -1, Y -1, 4, 4);} prevpoin = MyPoint;} b. save (p. Response. OutputStream, Imageformat. JPEG);} linechart () {g. di Spose (); b. dispose ();}}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private () {this.load = new system.eventhandler (this.page_load);

} #Endregion}}}

转载请注明原文地址:https://www.9cbs.com/read-50792.html

New Post(0)