华恒Mes鼎捷代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

320 lines
13 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using DevExpress.XtraCharts;
  10. using DevExpress.Utils;
  11. namespace ICSSoft.Frame.WatchPanel
  12. {
  13. public partial class FormWatch2 : Form
  14. {
  15. CtrlAutoSize autosize;
  16. public FormWatch2()
  17. {
  18. InitializeComponent();
  19. //控件随窗体变大
  20. this.Resize += new EventHandler(label2_Resize);
  21. autosize = new CtrlAutoSize(this); //实例化对象并传递"this"
  22. autosize.setTag(this); //控件随窗体变大
  23. DataTable dt = CreateData();
  24. this.chartControl2.DataSource = dt;
  25. CreatChart2(dt); //创建柱形图
  26. this.chartControl2.DataSource = dt;
  27. CreatChart3(dt); //创建柱形图
  28. this.chartControl1.DataSource = dt;
  29. CreatChart(dt); //创建饼状图
  30. #region 颜色设置
  31. this.BackColor = Color.FromArgb(47, 46, 42);
  32. chartControl1.BackColor = Color.FromArgb(47, 46, 42);
  33. label27.BackColor = Color.FromArgb(68, 86, 96);
  34. chartControl2.BackColor = Color.FromArgb(68, 86, 96);
  35. label28.BackColor = Color.FromArgb(68, 86, 96);
  36. label29.BackColor = Color.FromArgb(68, 86, 96);
  37. label30.BackColor = Color.FromArgb(68, 86, 96);
  38. label31.BackColor = Color.FromArgb(68, 86, 96);
  39. label32.BackColor = Color.FromArgb(68, 86, 96);
  40. label33.BackColor = Color.FromArgb(68, 86, 96);
  41. label34.BackColor = Color.FromArgb(68, 86, 96);
  42. label36.BackColor = Color.FromArgb(68, 86, 96);
  43. label37.BackColor = Color.FromArgb(68, 86, 96);
  44. label38.BackColor = Color.FromArgb(68, 86, 96);
  45. chartControl3.BackColor = Color.FromArgb(68, 86, 96);
  46. #endregion
  47. }
  48. #region 控件随窗体变大的类
  49. public class CtrlAutoSize
  50. {
  51. System.Windows.Forms.Form thisForm;
  52. private float x, y;
  53. float newx, newy;
  54. public CtrlAutoSize(System.Windows.Forms.Form form)
  55. {
  56. thisForm = form;
  57. x = thisForm.Width;
  58. y = thisForm.Height;
  59. }
  60. public void setTag(Control cons)
  61. {
  62. foreach (Control con in cons.Controls)
  63. {
  64. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  65. if (con.Controls.Count > 0)
  66. {
  67. setTag(con);
  68. }
  69. }
  70. }
  71. public void setControls(Control cons)
  72. {
  73. newx = cons.Width / x;
  74. newy = cons.Height / y;
  75. foreach (Control con in cons.Controls)
  76. {
  77. string[] mytag = con.Tag.ToString().Split(new char[] { (':') });
  78. float a = Convert.ToSingle(mytag[0]) * newx;
  79. con.Width = (int)a;
  80. a = Convert.ToSingle(mytag[1]) * newy;
  81. con.Height = (int)a;
  82. a = Convert.ToSingle(mytag[2]) * newx;
  83. con.Left = (int)a;
  84. a = Convert.ToSingle(mytag[3]) * newy;
  85. con.Top = (int)a;
  86. Single currentSize = Convert.ToSingle(mytag[4]) * newy;
  87. con.Font = new System.Drawing.Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  88. if (con.Controls.Count > 0)
  89. {
  90. setControls(con);
  91. }
  92. }
  93. }
  94. }
  95. #endregion
  96. private void label2_Resize(object sender, EventArgs e)
  97. {
  98. autosize.setControls(this);
  99. }
  100. private void timer1_Tick(object sender, EventArgs e)
  101. {
  102. this.label9.Text = DateTime.Now.ToString();
  103. }
  104. private void button3_Click(object sender, EventArgs e)
  105. {
  106. this.Close();
  107. }
  108. private DataTable CreateData()
  109. {
  110. DataTable dt = new DataTable();
  111. dt.Columns.Add(new DataColumn("类型"));
  112. dt.Columns.Add(new DataColumn("2005-1月", typeof(decimal)));
  113. dt.Columns.Add(new DataColumn("2005-2月", typeof(decimal)));
  114. dt.Columns.Add(new DataColumn("2005-3月", typeof(decimal)));
  115. dt.Columns.Add(new DataColumn("2005-4月", typeof(decimal)));
  116. dt.Columns.Add(new DataColumn("2005-5月", typeof(decimal)));
  117. dt.Columns.Add(new DataColumn("2005-6月", typeof(decimal)));
  118. dt.Rows.Add(new object[] { "员工人数", 437, 437, 414, 397, 387, 378 });
  119. dt.Rows.Add(new object[] { "人均月薪", 3964, 3961, 3979, 3974, 3967, 3972 });
  120. dt.Rows.Add(new object[] { "成本TEU", 3104, 1339, 3595.8, 3154.5, 2499.8, 3026 });
  121. dt.Rows.Add(new object[] { "人均生产率", 7.1, 3.06, 8.69, 7.95, 6.46, 8.01 });
  122. dt.Rows.Add(new object[] { "占2005年3月人数比例", 1.06, 1.06, 1, 0.96, 0.93, 0.91 });
  123. return dt;
  124. }
  125. private void CreatChart(DataTable dt)
  126. {
  127. chartControl1.Series.Clear();
  128. chartControl1.Legend.BackColor = Color.FromArgb(68, 86, 96);
  129. chartControl1.Legend.Border.Visible = false;
  130. // 柱状图里的第一个柱
  131. Series Series1 = CreateSeries1("员工人数", ViewType.Pie, dt, 0);
  132. Series1.Label.BackColor = Color.FromArgb(47, 46, 42);
  133. Series1.Label.Border.Visible = false;
  134. //Series Series1 = new Series("员工人数", ViewType.Bar);
  135. Series1.DataSource = dt;
  136. Series1.ArgumentScaleType = ScaleType.Qualitative;
  137. //Series1.ArgumentDataMember = "2005-1月";
  138. // 以哪个字段进行显示
  139. Series1.View.Color = Color.Yellow;
  140. Series1.ValueScaleType = ScaleType.Numerical;
  141. // 柱状图里的柱的取值字段
  142. Series1.ValueDataMembers[0] = "2005-1月";
  143. Series1.ArgumentDataMember = "类型";
  144. Series1.LegendPointOptions.PointView = PointView.Argument;
  145. //SetPiePercentage(Series1);
  146. // 柱状图里的第二柱
  147. //Series Series2 = CreateSeries2("人均月薪", ViewType.Pie, dt, 1);
  148. ////Series Series2 = new Series("", ViewType.Bar);
  149. //Series2.DataSource = dt;
  150. //Series2.View.Color = Color.Lime;
  151. //Series2.ArgumentScaleType = ScaleType.Qualitative;
  152. ////Series2.Vi = ;
  153. ////Series2.ArgumentDataMember = "2005-2月";
  154. //Series2.ValueScaleType = ScaleType.Numerical;
  155. //Series2.Label.LineVisible = true;
  156. //Series2.ValueDataMembers.AddRange(new string[] { "2005-2月" });
  157. chartControl1.Series.Add(Series1);
  158. //chartControl1.Series.Add(Series2);
  159. chartControl1.Legend.BackColor = Color.FromArgb(47, 46, 42);
  160. chartControl1.Legend.Border.Visible = false;
  161. }
  162. //public void SetPiePercentage(this Series series)
  163. //{
  164. // if (series.View is PieSeriesView)
  165. // {
  166. // ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent = true;
  167. // ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
  168. // ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision = 0;
  169. // }
  170. //}
  171. private void CreatChart2(DataTable dt)
  172. {
  173. chartControl2.Series.Clear();
  174. chartControl2.Legend.BackColor = Color.FromArgb(68, 86, 96);
  175. chartControl2.Legend.Border.Visible = false;
  176. // 柱状图里的第一个柱
  177. Series Series1 = CreateSeries2("员工人数", ViewType.Bar, dt, 0);
  178. BarSeriesView sv1 = (BarSeriesView)Series1.View;
  179. sv1.FillStyle.FillMode = FillMode.Solid;
  180. //Series Series1 = new Series("员工人数", ViewType.Bar);
  181. Series1.DataSource = dt;
  182. Series1.ArgumentScaleType = ScaleType.Qualitative;
  183. //Series1.ArgumentDataMember = "2005-1月";
  184. // 以哪个字段进行显示
  185. Series1.View.Color = Color.Yellow;
  186. Series1.ValueScaleType = ScaleType.Numerical;
  187. // 柱状图里的柱的取值字段
  188. Series1.ValueDataMembers.AddRange(new string[] { "2005-1月" });
  189. // 柱状图里的第二柱
  190. Series Series2 = CreateSeries2("人均月薪", ViewType.Bar, dt, 1);
  191. //Series Series2 = new Series("", ViewType.Bar);
  192. Series2.DataSource = dt;
  193. Series2.View.Color = Color.Lime;
  194. Series2.ArgumentScaleType = ScaleType.Qualitative;
  195. //Series2.Vi = ;
  196. //Series2.ArgumentDataMember = "2005-2月";
  197. Series2.ValueScaleType = ScaleType.Numerical;
  198. Series2.Label.LineVisible = true;
  199. Series2.ValueDataMembers.AddRange(new string[] { "2005-2月" });
  200. chartControl2.Series.Add(Series1);
  201. chartControl2.Series.Add(Series2);
  202. XYDiagram diagram = (XYDiagram)chartControl2.Diagram;
  203. diagram.DefaultPane.BackColor = Color.FromArgb(68, 86, 96);
  204. }
  205. private void CreatChart3(DataTable dt)
  206. {
  207. chartControl3.Series.Clear();
  208. chartControl3.Legend.BackColor = Color.FromArgb(68, 86, 96);
  209. chartControl3.Legend.Border.Visible = false;
  210. // 柱状图里的第一个柱
  211. Series Series1 = CreateSeries2("员工人数", ViewType.Bar, dt, 0);
  212. //Series Series1 = new Series("员工人数", ViewType.Bar);
  213. Series1.DataSource = dt;
  214. Series1.ArgumentScaleType = ScaleType.Qualitative;
  215. //Series1.ArgumentDataMember = "2005-1月";
  216. // 以哪个字段进行显示
  217. Series1.View.Color = Color.Yellow;
  218. Series1.ValueScaleType = ScaleType.Numerical;
  219. // 柱状图里的柱的取值字段
  220. Series1.ValueDataMembers.AddRange(new string[] { "2005-1月" });
  221. // 柱状图里的第二柱
  222. Series Series2 = CreateSeries2("人均月薪", ViewType.Bar, dt, 1);
  223. //Series Series2 = new Series("", ViewType.Bar);
  224. Series2.DataSource = dt;
  225. Series2.View.Color = Color.Lime;
  226. Series2.Label.TextColor = Color.Yellow;
  227. Series2.ArgumentScaleType = ScaleType.Qualitative;
  228. //Series2.ArgumentDataMember = "2005-2月";
  229. Series2.ValueScaleType = ScaleType.Numerical;
  230. Series2.ValueDataMembers.AddRange(new string[] { "2005-2月" });
  231. chartControl3.Series.Add(Series1);
  232. chartControl3.Series.Add(Series2);
  233. XYDiagram diagram = (XYDiagram)chartControl3.Diagram;
  234. diagram.DefaultPane.BackColor = Color.FromArgb(68, 86, 96);
  235. }
  236. //创建饼状图对象
  237. private Series CreateSeries1(string caption, ViewType viewType, DataTable dt, int rowIndex)
  238. {
  239. Series series = new Series(caption, viewType);
  240. for (int i = 1; i < dt.Columns.Count; i++)
  241. {
  242. string argument = dt.Columns[i].ColumnName;//参数名称
  243. decimal value = (decimal)dt.Rows[rowIndex][i];//参数值
  244. series.Points.Add(new SeriesPoint(argument, value));
  245. }
  246. return series;
  247. }
  248. //创建柱形图对象
  249. private Series CreateSeries2(string caption, ViewType viewType, DataTable dt, int rowIndex)
  250. {
  251. Series series = new Series(caption, viewType);
  252. for (int i = 1; i < dt.Columns.Count; i++)
  253. {
  254. string argument = dt.Columns[i].ColumnName;//参数名称
  255. decimal value = (decimal)dt.Rows[rowIndex][i];//参数值
  256. series.Points.Add(new SeriesPoint(argument, value));
  257. }
  258. BarSeriesView sv1 = (BarSeriesView)series.View;
  259. sv1.FillStyle.FillMode = FillMode.Solid;
  260. sv1.BarWidth = 0.5;
  261. //柱形上的标签
  262. series.LabelsVisibility = DefaultBoolean.True;
  263. series.Label.Border.Visible = false;
  264. series.Label.BackColor = Color.FromArgb(68, 86, 96);
  265. series.Label.TextColor = Color.White;
  266. series.Label.LineVisible = false;
  267. series.Label.LineLength = 4;
  268. return series;
  269. }
  270. private void FormWatch2_Load(object sender, EventArgs e)
  271. {
  272. }
  273. }
  274. }