Преглед изворни кода

图表绘制基础公用方法

Hcsy пре 8 година
родитељ
комит
eb4383308a
3 измењених фајлова са 66 додато и 22 уклоњено
  1. 32 4
      UAS-MES/Form1.Designer.cs
  2. 3 18
      UAS-MES/Form1.cs
  3. 31 0
      UAS-MES/PublicMethod/BaseUtil.cs

+ 32 - 4
UAS-MES/Form1.Designer.cs

@@ -31,11 +31,15 @@
             System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
             System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
             System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
+            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+            System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
+            System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
             this.button1 = new System.Windows.Forms.Button();
             this.button2 = new System.Windows.Forms.Button();
             this.ct_coll = new System.Windows.Forms.DataVisualization.Charting.Chart();
             this.paintpanel = new System.Windows.Forms.Panel();
+            this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
             this.enterTextBox2 = new UAS_MES.CustomControl.TextBoxWithIcon.EnterTextBox();
             this.valueLabel1 = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.normalButton2 = new UAS_MES.CustomControl.ButtonUtil.NormalButton();
@@ -45,6 +49,7 @@
             this.numOnlyTextBox1 = new UAS_MES.CustomControl.TextBoxWithIcon.NumOnlyTextBox();
             this.blurSearch1 = new UAS_MES.CustomControl.TextBoxWithIcon.BlurSearch();
             ((System.ComponentModel.ISupportInitialize)(this.ct_coll)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.TestDGV)).BeginInit();
             this.SuspendLayout();
             // 
@@ -74,12 +79,13 @@
             this.ct_coll.BackHatchStyle = System.Windows.Forms.DataVisualization.Charting.ChartHatchStyle.Cross;
             this.ct_coll.BackImageTransparentColor = System.Drawing.SystemColors.Control;
             this.ct_coll.BorderlineColor = System.Drawing.SystemColors.Control;
+            chartArea1.CursorX.IsUserEnabled = true;
             chartArea1.Name = "ChartArea1";
             this.ct_coll.ChartAreas.Add(chartArea1);
             legend1.Enabled = false;
             legend1.Name = "Legend1";
             this.ct_coll.Legends.Add(legend1);
-            this.ct_coll.Location = new System.Drawing.Point(704, 0);
+            this.ct_coll.Location = new System.Drawing.Point(34, 206);
             this.ct_coll.Margin = new System.Windows.Forms.Padding(2);
             this.ct_coll.Name = "ct_coll";
             this.ct_coll.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
@@ -91,18 +97,35 @@
             series1.LegendText = "#VALX";
             series1.Name = "Series1";
             this.ct_coll.Series.Add(series1);
-            this.ct_coll.Size = new System.Drawing.Size(214, 173);
+            this.ct_coll.Size = new System.Drawing.Size(50, 91);
             this.ct_coll.TabIndex = 5;
             this.ct_coll.Text = "chart1";
             // 
             // paintpanel
             // 
-            this.paintpanel.Location = new System.Drawing.Point(46, 210);
+            this.paintpanel.Location = new System.Drawing.Point(46, 535);
             this.paintpanel.Name = "paintpanel";
-            this.paintpanel.Size = new System.Drawing.Size(816, 335);
+            this.paintpanel.Size = new System.Drawing.Size(98, 10);
             this.paintpanel.TabIndex = 13;
             this.paintpanel.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
             // 
+            // chart1
+            // 
+            chartArea2.Name = "ChartArea1";
+            this.chart1.ChartAreas.Add(chartArea2);
+            legend2.Name = "Legend1";
+            this.chart1.Legends.Add(legend2);
+            this.chart1.Location = new System.Drawing.Point(132, 216);
+            this.chart1.Name = "chart1";
+            series2.ChartArea = "ChartArea1";
+            series2.IsValueShownAsLabel = true;
+            series2.Legend = "Legend1";
+            series2.Name = "Series1";
+            this.chart1.Series.Add(series2);
+            this.chart1.Size = new System.Drawing.Size(739, 300);
+            this.chart1.TabIndex = 17;
+            this.chart1.Text = "chart1";
+            // 
             // enterTextBox2
             // 
             this.enterTextBox2.AllPower = null;
@@ -121,8 +144,10 @@
             // valueLabel1
             // 
             this.valueLabel1.AutoSize = true;
+            this.valueLabel1.CutLength = null;
             this.valueLabel1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.valueLabel1.Location = new System.Drawing.Point(271, 170);
+            this.valueLabel1.MaximumSize = new System.Drawing.Size(200, 0);
             this.valueLabel1.Name = "valueLabel1";
             this.valueLabel1.Size = new System.Drawing.Size(0, 21);
             this.valueLabel1.TabIndex = 14;
@@ -227,6 +252,7 @@
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(929, 590);
+            this.Controls.Add(this.chart1);
             this.Controls.Add(this.enterTextBox2);
             this.Controls.Add(this.valueLabel1);
             this.Controls.Add(this.paintpanel);
@@ -242,6 +268,7 @@
             this.Text = "Form1";
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.ct_coll)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.TestDGV)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
@@ -265,5 +292,6 @@
         private System.Windows.Forms.Panel paintpanel;
         private CustomControl.ValueLabel.ValueLabel valueLabel1;
         private CustomControl.TextBoxWithIcon.EnterTextBox enterTextBox2;
+        private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
     }
 }

+ 3 - 18
UAS-MES/Form1.cs

@@ -56,7 +56,8 @@ namespace UAS_MES
             blurSearch1.TableName = "Make";
             blurSearch1.Field = "ma_code";
             DataHelper dh = new DataHelper();
-            ViewChart((DataTable)dh.ExecuteSql("select nvl(ms_nextstepcode ,'已完工')ms_nextstepcode ,count(*) from  makeserial left join makecraftdetail on ms_makecode=mcd_macode  and ms_nextstepcode =mcd_nextstepcode where ms_makecode='MB17050022' group by ms_nextstepcode", "select"), "TExt");
+            DataTable _dt = (DataTable)dh.ExecuteSql("select count(ms_code) as ms_code_sum,(to_char (ms_indate,'yyyy-mm-dd')) ms_date from MAKESERIAL GROUP BY (to_char (ms_indate,'yyyy-mm-dd')) order by (to_char (ms_indate,'yyyy-mm-dd')) asc", "select");
+            BaseUtil.ViewChart(chart1, _dt,SeriesChartType.Line, "datetitle", "ms_date", "ms_code_sum","生产日期","生产数");
             dt = (DataTable)dh.ExecuteSql("select ma_salecode,MA_STATUS from make where MA_SALECODE = 'TB17040014'", "select");
             Step = new Dictionary<int, string>();
             for (int i = 0; i < dt.Rows.Count + 2; i++)
@@ -76,23 +77,7 @@ namespace UAS_MES
 
         }
 
-        private void ViewChart(DataTable _dt, string _title)
-        {
-            List<string> xData = new List<string>();
-            List<int> yData = new List<int>();
-            for (int i = 0; i < _dt.Rows.Count; i++)
-            {
-                xData.Add(_dt.Rows[i]["ms_nextstepcode"].ToString());
-                yData.Add(int.Parse(_dt.Rows[i]["count(*)"].ToString()));
-            }
-            ct_coll.Series[0]["PieLineColor"] = "Red";//绘制黑色的连线。
-            this.ct_coll.Series[0].ToolTip = "#VAL{D}件";//鼠标移动到上面显示的文字  
-            this.ct_coll.Series[0].BackSecondaryColor = Color.DarkCyan;
-            this.ct_coll.Series[0].BorderColor = Color.DarkOliveGreen;
-            this.ct_coll.Series[0].LabelBackColor = Color.Transparent;
-            ct_coll.ChartAreas[0].Area3DStyle.Enable3D = true;
-            ct_coll.Series[0].Points.DataBindXY(xData, yData);
-        }
+       
 
         private void normalButton2_Click(object sender, EventArgs e)
         {

+ 31 - 0
UAS-MES/PublicMethod/BaseUtil.cs

@@ -3,6 +3,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
+using System.Drawing;
 using System.IO;
 using System.Net;
 using System.Net.Sockets;
@@ -10,6 +11,7 @@ using System.Reflection;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;
+using System.Windows.Forms.DataVisualization.Charting;
 using UAS_MES.CustomControl.DataGrid_View;
 using UAS_MES.CustomControl.GroupBoxWithBorder;
 using UAS_MES.CustomControl.TextBoxWithIcon;
@@ -934,5 +936,34 @@ namespace UAS_MES.PublicMethod
             }
             return ndt;
         }
+
+        /// <summary>
+        /// 图表绘制公共方法样本
+        /// </summary>
+        /// <param name="chart1"></param>
+        /// <param name="_dt"></param>
+        /// <param name="seriesChartType"></param>
+        /// <param name="_title"></param>
+        /// <param name="XValueMember"></param>
+        /// <param name="YValueMembers"></param>
+        /// <param name="Xname"></param>
+        /// <param name="Yname"></param>
+        public static void ViewChart(Chart chart1, DataTable _dt, SeriesChartType seriesChartType, string _title, string XValueMember, string YValueMembers, string Xname, string Yname)
+        {
+            chart1.Series[0].ChartType = seriesChartType;
+            chart1.DataSource = _dt;
+            chart1.Series[0].MarkerStyle = MarkerStyle.Circle;
+            chart1.Series[0].MarkerSize = 8;
+            chart1.Series[0].XValueMember = XValueMember;
+            chart1.Series[0].YValueMembers = YValueMembers;
+            chart1.Series[0].Label = "#VAL";
+            chart1.Series[0].LabelToolTip = Xname + ": #VAL\r\n " + Yname + " #VALX";
+            chart1.Series[0].BackSecondaryColor = Color.DarkCyan;
+            chart1.Series[0].BorderColor = Color.DarkOliveGreen;
+            chart1.Series[0].LabelBackColor = Color.Transparent;
+            chart1.Series[0].LegendText = Yname;
+            chart1.Legends[0].Title = _title;
+            //chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
+        }
     }
 }