Cylindrical chart and line chart pie chart control (original)

xiaoxiao2021-03-05  26

Using system.collections; using system.drawing; using system.data; using system.windows.form; using system.xml;

Namespace ChartControl {///

/// ChartControl 1.0's summary description. This control is a drawing, generating a chart according to the data of the XML document. /// Currently draw 2 dimensional graphs and 3 dimensional graphic graphs and line charts. Han Yongcun 5APR2005 was made. /// Cylindrical graph This "add key =" diagramType "in the XML file is modified to Histogram /// Palemount," Add Key = "DiagramType" in the XML file "" "" Figure Please modify the "add key =" diagramType "in the XML file to the CAKYDIAGRAM / / / XML file cannot modify the name, need to execute the file with your program in the same directory. /// public class ChartControl: System.Windows.Forms.UserControl {private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; / // /// The required designer variable. /// private system.componentmodel.container components = null;

Public ChartControl () {// This call is required for the Windows.Forms Form Designer. InitializationComponent ();

// Todo: Add any initialization after INitComponent call

}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) Components.dispose ();} Base.Dispose (Disposing);

#REGION component designer generated code ///

/// designer supports the required method - Do not use the code editor // to modify the contents of this method. /// private (this.label1 = new system.windows.forms.label (); this.label2 = new system.windows.forms.label (); this.label3 = new system. Windows.Forms.Label (); this.suspendlayout (); // // label1 // this.label1.location = new system.drawing.point (104, 16); this.label1.name = "label1"; THIS .label1.size = new system.drawing.size (160, 24); this.label1.tabindex = 0; this.label1.text = "label1"; // // label2 // this.label2.Location = new system .Drawing.point (8, 56); this.label2.name = "label2"; this.label2.tabindex = 1; this.label2.text = "label2"; /// Label3 // this.label3.location = new System.Drawing.Point (288, 320); this.label3.Name = "label3"; this.label3.TabIndex = 2; this.label3.Text = "label3"; // // ChartControl // this. BACKCOLOR = system.drawing.color.white; this.controls.add (this.label3); this.controls.add (this.label2); this.controls.add (this.label1); this.name = " ChartControl "; this.size = new system.drawing.size (448, 360); this.Load = new system.EventHandler (this.chartcontrol_load); this.ResumeLayout (false);} #ENDREGION

#Region Read and write a few small functions for XML files, 2005 4 2 by HYC

public void SetXmlFileValue (string xmlPath, string AppKey, string AppValue) // write XMLPath file path file name, AppKey is Key Name, AppValue is Value {XmlDocument xDoc = new XmlDocument (); xDoc.Load (xmlPath); XmlNode xNode XMLELEMENT Xelem1; XMLELEMENT Xelem2;

XNode = xdoc.selectsinglenode ("// appsettings"); Xelem1 = (XMLELEMENT) XNode.selectsinglenode ("// add [@ key = '" appkey "); if (Xlem1! = null) {XElem1 .SetaTRibute ("Value", AppValue;} else {xlem2 = xdoc.createElement ("add"); Xelem2.SetaTRibute ("key", appkey); Xelem2.SetAttribute ("Value", appValue; xnode.appendchild Xelem2);} xdoc.save (xmlpath);

public void GetXmlFileValue (string xmlPath, string AppKey, ref string AppValue) // read XMLPath file path file name, AppKey is Key Name, AppValue is Value {XmlDocument xDoc = new XmlDocument (); xDoc.Load (xmlPath); XmlNode XNode; XMLELEMENT Xelem1;

XNode = xdoc.selectsinglenode ("// appsettings");

Xelem1 = (XMLELEMENT) xNode.selectsinglenode ("// add [@ key = '" appkey ""); if (Xelem1! = null) {appValue = Xelem1.GetaTribute ("value");} else} // MessageBox.show ("there is not anyournal!");

}

#ndregion

#Region Variable Declaration, 2005 4 4 by HYC

Public int formwidth; public int form = 1; public int mark = 1; public int min = 1; public int jNum = 1; // Dighter PUBLIC INT POLICEBOLD; public int Heightxs = 100; // High Coefficient Public int [] startangl = new int [100]; // Start angle public int [] sweepangl = new int [100]; // Cross the radian public int allsweep; public int kuandu; public int in; public int in; 100, 100]; public int [100, 100]; public int [] yy = new int [100, 100]; public string [] type = new string [100]; public string [,] typeValue = new string [100,100]; public string appvalue; public string pathFileName = System.Windows .Forms .Application.StartupPath "// XMLChart.xml"; System.Windows .Forms .Label [] TypeNameLabel; System.Windows .Forms .Label [, ] TYPEVALUELABEL; #ENDREGION

#Region Custom Function, 2005 4 4 by HYC

public void AllBegain () // All initialization {FormHeight = this.Height; FormWidth = this.Width; GetXmlFileValue (PathFileName, "DiagramName", ref appvalue); label1.Text = appvalue "(this is a control chart Beta)"; GetXmlFileValue (PathfileName, "YNAME", Ref appValue; label2.text = appValue; getXmlFileValue (pathfilename, "xname", ref appval); label3.text = appValue;

Label1.autosize = true; label1.top = 5; label1.LEFT = (FormWidth-label1.width) / 2; label2.autosize = true; label3.autosize = true; label2.top = 15; label2.Left = 5; Label3.top = FormHeight-10; label3.left = formwidth-label3.width-5;

GetXmlFileValue (PathfileName, "NUM", Ref AppValue; Num = Int32.Parse (AppValue);

GetXmlFileValue (PathfileName, "JNUM", Ref appValue; jnum = int32.parse (appValue);

}

Public void histogrambegain () // histogram initialization {for (int i = 1; i <= Num; i ) {getXmlfileValue (PathFileName, "ID" i.toString (), Ref typeename [i]); for (int J = 1; j <= jnum; j ) {getXmlFileValue (PathFileName, "ID" J.Tostring () "Num" i.tostring (), ref typevalue [j, i]);}} Polebold = FormWidth * 2 / (3 * Num * jnum); max = int32.parse (TypeValue [1,1]); min = int32.parse (TypeValue [1,1]); for (int i = 1; i <= NUM; i ) {for (int J = 1; j <= jnum; j ) {if (INT32.PARS (TypeValue [J, I])> max) {max = int32.parse (TypeValue [J, I]);} IF (INT32.PARSE (TypeValue [J, I])

For (int i = 1; i <100; i ) {if (Max> (FormHeight-50)) {heightxs = heightxs / 2; max = max / 2;} IF (MAX <(FormHeight-50) / 2) {Heightxs = heightxs * 2; max = max * 2;} IF (MAX <(FormHeight-50) &&m> (FormHeight-50) / 2) {Break;}}

For (int i = 1; i <= NUM; i ) {for (int J = 1; j <= jnum; j ) {x [j, i] = (label3.Left - (label2.left label2.width ) / Num * i- (label2.width) (Polebold 1) * (J-1) -Label3.Width; // ???? y [j, i] = label3.top- 5- (INT32.PARS (TypeValue [J, I]) * Heightxs / 100); YY [J, I] = Int32.Parse (TypeValue [J, I]); YY [J, I] = YY [J, I] * heightxs / 100;}}

Typenamelabel = new system.windows .forms.label [100];

For (int i = 1; i <= NUM; i ) {typenamelabel [i] = new label (); typenamelabel [i] .top = label3.top; typenamelabel [i] .text = Typename [i]; typeenamelabel [ I] .autosize = true; typenamelabel [i] .left = x [1, i] polebold * jnum / 2; this.controls .add (TypeNameLabel [i]);} typevaluelabel = new system.windows .forms.label [100,100]; for (int i = 1; i <= NUM; i ) {for (int J = 1; j <= jnum; j ) {TypeValueLabel [J, I] = new label (); typevaluelabel [J, I] .top = y [j, i] -20; TypeValueLabel [J, I] .text = TypeValue [J, I]; TypeValueLabel [J, I] .autosize = true; TypeValueLabel [J, I] .left = X [J, I]; this.Controls .add (TypeValueLabel [J, I]);}}}

Public void flexdiagrambegain () // flex diagram initialization {for (int i = 1; i <= Num; i ) {getXmlfileValue (PathFileName, "ID" i.toString (), Ref typeename [i]); for (int J = 1; j <= jnum; j ) {getXmlFileValue (PathFileName, "ID" J.Tostring () "NUM" i.toString (), ref typevalue [j, i]);}} typeenamelabel = new System.windows .forms.Label [100];

For (int i = 1; i <= NUM; i ) {typenamelabel [i] = new label (); typenamelabel [i] .top = label3.top; typenamelabel [i] .text = Typename [i]; typeenamelabel [ I] .autosize = true; typenamelabel [i] .left = (label3.Left - (label2.left label2.width) / Num * i- (label2.Left label2.width) --TypenameLabel [i] .width / 2; this.controls .add (TypenAmeLabel [i]);} max = int32.parse (TypeValue [1,1]); min = int32.parse (TypeValue [1,1]); for (int i = 1 i <= NUM; i ) {for (int J = 1; j <= jnum; j ) {if (INT32.PARS (TypeValue [J, I])> max) {max = int32.parse (TypeValue " , I]);} if (int32.Parse (TypeValue [J, I]) (FormHeight-50) / 2) {Break;}}

For (int i = 1; i <= NUM; i ) {for (int J = 1; j <= jnum; j ) {x [j, i] = (label3.Left - (label2.left label2.width )) / Num * i- (label2.width); y [j, i] = label3.top-5- (INT32.PARS (TypeValue [J, I]) * heightxs / 100); yy [ J, I] = int32.Pars (TypeValue [J, I]); YY [J, I] = YY [J, I] * Heightxs / 100;}} typevaluelabel = new system.windows .forms.label [100,100] ;

For (int i = 1; i <= NUM; i ) {for (int J = 1; j <= jnum; j ) {TypeValueLabel [J, I] = new label (); TypeValueLabel [J, I] .top = Y [J, I] -20; TypeValueLabel [J, I] .text = TypeValue [J, I]; TypeValueLabel [J, I] .autosize = true; TypeValueLabel [J, I] .left = (Label3.Left - (label2.Label2.Width) / Num * i- (label2.Left label2.width) --TypevalueLabel [J, I] .width / 2; this.controls .add (TypeValueLabel [J, I]) }}} Public void cakydiagrambegain () // Pie chart initialization {for (int i = 1; i <= Num; i ) {getXmlfileValue (PathFileName, "ID" i.toT7tring (), ref typeename [i] ); GetXmlFileValue (PathFileName, "ID1NUM" I.toString (), Ref typeValue [1, i]);}

For (int i = 1; i <= NUM; i ) {getXmlFileValue (PathFileName, "ID1NUM" i.toString (), ref appvalue; Sweepangl [i] = int32.parse (appValue);}

Allsweep = 0; for (int i = 1; i <= NUM; i ) {allsweep = allsweep sweepangl [i];}

For (int i = 1; i <= NUM; i ) {sweepangl [i] = (Sweepangl [i] * 360) / allsweep;

// Remove the White Int Tempsw; for (int J = 1; j <360; j ) {tempsw = 0; for (int i = 1; i <= NUM; i ) {tempsw = tempsw sweepangl [i]; } IF (TempsW <360) {for (INT K = 1; K <= 360-Tempsw; K ) {IF (k = 360) {BREAK;}}

Startangl [1] = 0; int TempallsWeep; for (int i = 2; i <= NUM; i ) {tempallsweep = 0; for (int J = 1; j <= I-1; j ) {Tempallsweep = Tempallsweep Sweepangl [J];} Startangl [I] = TempallsWeep;}} {knUndu = FormHEight * 2/3;} else {knUandu = FormWidth * 2/3;}

Double Angle;

Typenamelabel = new system.windows .forms.label [100]; for (int i = 1; i <= Num; i ) {angle = (360-startangl [i] 90-sweepangl [i] / 2) * 3.141592653579 / 180;

Typenamelabel [i] = new label (); typenamelabel [i] .top = (int) ((KUANDU 60) / 2 * Math.cos (Angle)) (FormHeight / 6 KUANDU / 2); TypenameLabel [i ] .Text = TypeName [i]; TypenameLabel [i] .autosize = true; typenamelabel [i] .left = (int) ((KUANDU 60) / 2 * math.sin (Angle)) (FormWidth / 6 KUANDU / 2); this.Controls .add (TypenAmelabel [i]);

TypevalueLabel = new system.windows .forms.label [100,100]; string tempstr1;

For (int i = 1; i <= NUM; i ) {tempstr1 = (int32.parse (TypeValue [1, I]) * 1.0 / allsweep * 100.0) .tostring () "; typevaluelabel [1, i] = new label (); typevaluelabel [1, i] .top = TypenameLabel [i] .top; typevaluelabel [1, i] .text = Tempstr1.substring (0,5) "%"; TypeValueLabel [1, i] .Autosize = true; typevaluelabel [1, i] .left = typenamelabel [i] .left typenamelabel [i] .width 2; this.Controls .add (TypeValueLabel [1, i]);}

}

#ndregion

Private void ChartControl_load (Object Sender, System.EventAndargs E) {Allbegain ();}

#Region Draw Diagram Function, 2005 4 4 by HYC

protected override void OnPaint (PaintEventArgs paintEvent) {Graphics g = paintEvent.Graphics; SolidBrush brush = new SolidBrush (Color.Blue); Pen pen = new Pen (Color.Black); Pen pen2 = new Pen (Color.DarkGray); SolidBrush [] bb; bb = new solidbrush [100]; bb [1] = new solid brush (color.darkred); bb [2] = new solidbrush (color.darkslateBlue); bb [3] = new solidbrush (color.darkgray) BB [4] = new solid.yellowgreen; bb [5] = new solidbrush (color.darksalmon); bb [6] = new solidbrush (color.darkorange); BB [7] = New Solidbrush (Color. Lightyellow; bb [8] = new solidbrush (color.slateBlue); bb [9] = new solidbrush (color.ble); bb [10] = new solidbrush (color.yellowgreen); bb [11] = new solidbrush Color.darkseagreen; bb [12] = new solidbrush; bb [13] = new solidbrush (color.darkturquoise); bb [14] = new solidbrush (color.darkviolet); bb [15] = new Solidbrush (color.deEppink);

Pen [] pp; pp = new pen [100]; pp [1] = new pen (color.darkred); PP [2] = new pen (color.darkslateBlue); pp [3] = new pen (color.darkgray ); PP [4] = new pen (color.yellowgreen); PP [5] = new pen (color.darksalmon); PP [6] = new pen (color.darkoRange); PP [7] = New Pen (Color .Lightyellow; pp [8] = new pen (color.slateBlue); PP [9] = new pen (color.ble); pp [10] = new pen (color.yellowgreen); pp [11] = new pen (Color.darkseagreen); PP [12] = new pen (color.darkslate); pp [13] = new pen (color.darkturquoise); PP [14] = new pen (color.darkviolet); PP [15] = new Pen (Color.DeepPink); GetXmlFileValue (pathFileName, "DiagramType", ref appvalue); switch (appvalue) {case "histogram": // bar graph HistogramBegain (); g.DrawLine (pen, label2.Left label2 .Width, label3.top-5, label3.left label3.width, label3.top-5); g.drawline (Pen, Label2.Left label2.width, label3.top-5, label2.left label2. Width, label2.top-5); for (int i = 1; i <= NUM; I ) {for (int J = 1; j <= jnum; j ) {g.fillRecta NGLE (BB [J], X [J, I], Y [J, I], Polebold, YY [J, I]);}} Break; Case "flexdiagram": // Pacing chart flexdiagrambegain (); g. Drawline (Pen, Label2.Left Label2.Width, Label3.top-5, Label3.Left Label3.Width, Label3.top-5); g.drawline (Pen, Label2.Left label2.width, label3.top -5, Label2.Left label2.width, label2.top-5);

For (int i = 1; i

DEFAULT:

Break;

}

#ndregion}}}

///

// XML file content, this file must be placed in the application directory, file name xmlchart.xml

< Add key = "NUM" value = "5" />

Value = "July" /> < Add key = "id2num7" value = "4" />

VALUE = "2" /> < Add key = "id4num3" value = "4" /> <

Add key = "id5num1" value = "2" /> < Add key = "id6num1" value = "2" /> < Add key = "id7num15" value = "2" />

Value = "1" /> < Add key = "id9num11" value = "8" /> <

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

New Post(0)