C # .net Written Chart Generation Class

xiaoxiao2021-03-31  230

Using system.data; using system.drawing; using system.drawing.drawing2d;

Namespace WebUI {///

/// chartbrush's summary description.

/// public class ChartBrush {private int map_width; // graph height private int map_height; // chart width private string map_name; // name of the chart private string group_field; // packet field private string [] sum_field; / / SF field private string group_name; // Packet name private string [] sum_name; // value name // #Region /// Constructor PUBLIC ChartBrush (int width, int hight) {// // Todo: here Add constructor logic // map_width = Width; map_height = Hight; Initialization ();} public ChartBrush () {map_width = 600; map_height = 400; Initialization ();} #endregion // // private void Initialization () {map_name = "Report Title";} // #Region ******* Property ************** ///

/// Chart width /// < / summary> public int map_width {get {return map_width;} set {map_width = value;}} /// /// chart height /// public int map_height {get {return map_height;} set {MAP_HEIGHT = value;}} /// /// Chart name /// public string map_name {get {return map_na ME;} set {map_name = value;}} /// /// Packet field name, packet /// public string group_field {set {group_field = value;}} // / /// summage field name, summarized ///////////////////////////////field {set {SUM_FIELD = value;}} /// /// 组 组 title Set the graph group header /// public string group_name {set {group_name = value;}} /// /// data title, set chart data title /// public string [ ] SUM_NAME {SET {SUM_NAME = Value;}} #ENDREGON / / / / /

/// Generate a flat column //// /// private void drawcharthistogram (data) {#Region basic parameter int ystat = 30; int linewidth = 8 ; Int UPSIDE = 30; int starboard = 30; brush [] brush = new brush [5]; brush [0] = brushes.red; brush [1] = brushes.blue; brush [2] = Brushes.yellow; brush [3] = brushes.green; brush [4] = brushes.darkcy; #ndregion // bitmap map = new bitmap (this.map_width, this.map_height); // #Region Draw Title Graphics G = Graphics.FromImage (Map); g.clear (color.white); g.drawRectangle (New Pen (brushes.burlywood), 0, 0, map_width-5, map_height-5); // Draw Title G.DrawString (THIS .map_name, New Font ("Song", 14), Brushes.black, New Point (50, 3)); //g.drawstring(Sum_name, New Font ("Song", 10), Brushes.red, New Point (0, this.map_height / 2))); g.drawstring (Group_name, New Font ("Song", 10), Brushes.Red, New Point (Map_Width / 2-10, Map_HEight-15)); // Draw X Axis g.drawline (New Pen (Brushes.Blue), New Point (YSTAT, MAP_HEIGHT-Hemline), New Point (Map_Width-Ystat-Starboard, Map_height-hemline))); // Draw Y-axis g.drawline (New Pen (Brushes.Blue), New Point (YSTAT, UPSIDE), New Point (YSTAT, MAP_HEIGHT-HEMLINE)); String Tablename = DT.TABLENAME; / / String Temp = "SELECT" THIS.GROUP_FIELD ", SUM (" this.sum_field ")" "from" Tablename "Group by" this.group_field ";"; #ndregion // datarow [] DRS = Dt.select (); int count = DRS.LENGTH; int wscale = (map_width-ystat-starboard) / count; // #Region calculation draw graphic coordinate value Double maxValue = 0; for (int i = 0; i

SUM_FIELD.LENGTH; J ) {if (i == 0 && j == 0) {MaxValue = double.PARSE (DRS [0] [Sum_field [0]]. TOSTRING ());} else {ix (Double.Parse (DRS [i] [sum_field [j]]. TOSTRING ())> maxValue) {maxValue = double.PARSE (DRS [i] [sum_field [j]]. toString ());}}}} Double Hscale = maxValue / Map_height-hemline-upside); int graduation = (map_height-hemline-upside) / 5; int factgraduation = (int) (maxValue / 5); #endregion // Draw graph #Region ********* *** g.drawstring ("0", New Font ("Song", 6), Brushes.red, New Point (YSTAT-15, MAP_HEIGHT-HEMLINE)); for (int i = 0; i <5; i ) ) {G.drawstring ((FactGraduation * (i 1)). Tostring (), New Font ("Song", 8), Brushes.red, New Point (YSTAT-15, MAP_HEIGHT-HEMLINE-GRADUATION * (i 1)))); g.drawline (New Pen (brushes.blue), New Point (YSTAT, MAP_HEIGHT-HEMLINE-GRADUATION * (i 1)), New Point (YSTAT 5, MAP_HEIGHT-HEMLINE-GRADUATION * (i 1)));} // int [] yvalue = new int [SUM_FIELD.LENGTH]; int [] xvalue = new int [SUM_FIELD.LENGTH]; for (int i = 0; i

(int) (wscale / 2- (SUM_FIELD.LENGTH * LINEWIDTH (SUM_FIELD.LENGTH-1) * 2.5) YSTAT WSCALE * i);} else {xvalue [j] = xvalue [j-1] linewidth * 2 5;} // xvalue = wscale;}} int m = 0; // Draw block for (int K = 0; k

//} ////

/// Generate flat pie chart /// /// private void Drawchatpie (DataTable DT) {//// the boundary int upsize = 50; int hemline = 50; int xcenter = map_width / 2; int ycenter = (map_height-upsize-hemline) / 2 upsize; int xpiesize = 300; int ypiesize = 280; int X = xcenter-xpiesize / 2-50; int y = ycenter-ypiesize / 2; brush [] brush = new brush [5]; brush [0] = brushes.red; brush [1] = brushes.blue; brush [2] = brushes. Yellow; brush [3] = brushes.green; brush [4] = brushes.darkcyan; // bitmap map = new bitmap (this.map_width, this.map_height); graphics g = graphics.fromImage (map); g.clear (Color.white); // Calculate the angle of the position of each section of the pie chart Try {data = SUM_FIELD.LENGTH; Double SUMVALUE = 0; for (int i = 0; i < Count; i ) {SUMVALUE = double.parse (DRS [this.sum_field [i]]. TOSTRING ());} int [] angle = new int [count 1]; angle [0] = 0; for (int) I = 1; i

// Start to draw G. DrawString (Map_Name, New Font ("Song", 14), Brushes.Black, New Point (20, 15)); g.drawRectangle (New Pen (Brushes.burlywood), 0, 0, Map_Width -5, map_height-5); for (int i = 0; i /// Generate PS graph /// /// Private void Drawchartps (DataTable DT) {#Region basic parameter int ystat = 30; // int lineWidth = 8; int = 30; int UPSIDE = 50; int starboard = 30; brush [] brush = new brush [5]; brush [0] = Brushes.red; brush [1] = brushes.blue; brush [2] = brushes.yellow; brush [3] = brushes.green; brush [4] = brushes.darkcyan; #ENDREGION / / bitmap map = new bitmap THIS.MAP_WIDTH, this.map_height); // #Region Draw Title Graphics G = Graphics.FromImage (Map);

g.drawRectangle (New Pen (Brushes.burlywood), 0, 0, Map_Width-1, Map_Height-1); // Draw Title g.drawstring (this.map_name, New Font " Song ", 14), brushes.black, new point (50, 3)); //g.drawstring(sum_name ,new font (" Song ", 10), Brushes.red, New Point (0, this.map_height / 2)); g.drawstring (Group_name, New Font ("Song", 10), Brushes.Red, New Point (Map_Width / 2-10, Map_HEIGHT-15)); // Draw X-axis g.drawline (New Pen (Brushes.blue), new point (YSTAT, MAP_HEIGHT-Hemline), new point (map_width-ystat-starboard, map_height-hemline)); // Draw Y-axis g.drawline (New Pen (brushes.blue), New Point, NEW POINT (YSTAT, UPSIDE), New Point (YSTAT, MAP_HEIGHT-HEMLINE)); // String Tablename = DT.TABLENAME; // String Temp = "SELECT" this.group_field ", SUM (" this.sum_field ")" "from" Tablename "Group by" this.group_field ";"; ";" DRS = DT.Select (); int count = drs.length; int wscale = (map_width-ystat-starboard) / count; // #Region /// calculate draw graphic coordinate value Double maxValue = 0; for (int i = 0; i maxValue) {maxValue = double.PARSE (DRS [i] [sum_field [j]]. Tostring ());}}}} Double HScale = (Map_Height- Hemline-Upside) / maxValue; // Diameter INT graduation = (MAP_HEIGHT-HEMLINE-UPSIDE) / 5; int factgraduation = (int) (maxValue / 5); #endregion // Draw graph #REGON ******* ****** g.drawstring ("0", New font ("Song"

, 6), brushes.red, new point (YSTAT-15, MAP_HEIGHT-HEMLIN)); for (int i = 0; i <5; i ) {g.drawstring ((FactGraduation * (i 1)). Tostring (), New Font ("Song", 8), Brushes.Red, New Point (YSTAT-15, MAP_HEIGHT-HEMLINE-GRADUATION * (i 1))); g.drawline (New Pen (brushes.blue), New Point (YSTAT, MAP_HEIGHT-HEMLINE-GRADUATION * (i 1)), New Point (YSTAT 5, MAP_HEIGHT-HEMLINE-GRADUATION * (i 1))));} // int [] yvalue = new int = Sum_field.lendth]; int [] xvalue = new int [amount = 0; for (int i = 0; i = 5) {k = 0;} IF (j == 0) { Xbegin = ystat wscale / 2; ybegin = map_height- (int) (Double.Parse (DRS [J]]. TOSTRING ()) * hscale) -ystat; xend = xbegin wscale; yend = map_height - (int) (DOUBLE.PARSE (DRS [J]]. TOSTRING ()) * hscale) -ystat;} else {xbegin = XEND; YBEGIN = YEND; Xend = Xbegin wscale; ye Nd = map_height- (int) (Double.Parse (DRS [J 1] [this.sum_field [i]]. TOSTRING ()) * hscale) -ystat;} if (i == 0) {g.drawstring DRS [J] [Group_field] .tostring (), New Font ("Song", 9), Brushes.Red, (Float) Xbegin, (Map_Height-Hemline)); if (j == count-2) {G.drawstring (DRS [J 1] [Group_field] .tostring (), New Font ("Song", 9), Brushes.Red, (Float) (Map_Height-Hemline);}} IF (j == count-2) {g.drawstring (DRS [J]]. Tostring (), New Font ("Song", 8), Brush [K], Xbegin, Ybegin-9) ;

g.drawstring (DRS [J 1] [SUM_FIELD [I]]. toString (), New Font ("Song", 8), Brush [K], XEND, YEND-9);} else {g.drawstring DRS [J]. Tostring (), New Font ("Song", 8), Brush [K], Xbegin, Ybegin-9);} g.drawline (New Pen (brush [k]) New Point (Xend, Yend);} k ;} // #ndregion // map.save (System.Web.httpContext.current.Response.OutputStream, System.drawing.Image. ImageFormat.Jpeg); //} public void drawChart (DataTable dt, ChartTypes.TypeSelect cty) {DataTable datatable = dt; switch (cty) {case ChartTypes.TypeSelect.N_Histogram: // DrawCharthistogram (datatable); // break; case CHARTTYPES.TYPESELECT.N_PIE: // Drawchartpie (DATATABLE); // Break; Case ChartTypes.typeselect.n_psCurve: // Drawchartps (DataTable); // Break;

} //}}

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

New Post(0)