Using system.collections; using system.drawing; using system.data; using system.windows.form; using system.xml;
Namespace ChartControl {///
Public ChartControl () {// This call is required for the Windows.Forms Form Designer. InitializationComponent ();
// Todo: Add any initialization after INitComponent call
}
///
#REGION component designer generated code ///
#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]) 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 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 XML Version = "1.0" encoding = "UTF-8"?> Value = "July" /> VALUE = "2" /> Add key = "id5num1" value = "2" /> Value = "1" />