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
320 lines
13 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraCharts;
|
|
using DevExpress.Utils;
|
|
|
|
namespace ICSSoft.Frame.WatchPanel
|
|
{
|
|
public partial class FormWatch2 : Form
|
|
{
|
|
CtrlAutoSize autosize;
|
|
public FormWatch2()
|
|
{
|
|
InitializeComponent();
|
|
//控件随窗体变大
|
|
this.Resize += new EventHandler(label2_Resize);
|
|
autosize = new CtrlAutoSize(this); //实例化对象并传递"this"
|
|
autosize.setTag(this); //控件随窗体变大
|
|
|
|
DataTable dt = CreateData();
|
|
this.chartControl2.DataSource = dt;
|
|
CreatChart2(dt); //创建柱形图
|
|
|
|
this.chartControl2.DataSource = dt;
|
|
CreatChart3(dt); //创建柱形图
|
|
|
|
this.chartControl1.DataSource = dt;
|
|
CreatChart(dt); //创建饼状图
|
|
|
|
#region 颜色设置
|
|
this.BackColor = Color.FromArgb(47, 46, 42);
|
|
chartControl1.BackColor = Color.FromArgb(47, 46, 42);
|
|
label27.BackColor = Color.FromArgb(68, 86, 96);
|
|
chartControl2.BackColor = Color.FromArgb(68, 86, 96);
|
|
label28.BackColor = Color.FromArgb(68, 86, 96);
|
|
label29.BackColor = Color.FromArgb(68, 86, 96);
|
|
label30.BackColor = Color.FromArgb(68, 86, 96);
|
|
label31.BackColor = Color.FromArgb(68, 86, 96);
|
|
label32.BackColor = Color.FromArgb(68, 86, 96);
|
|
label33.BackColor = Color.FromArgb(68, 86, 96);
|
|
label34.BackColor = Color.FromArgb(68, 86, 96);
|
|
label36.BackColor = Color.FromArgb(68, 86, 96);
|
|
label37.BackColor = Color.FromArgb(68, 86, 96);
|
|
label38.BackColor = Color.FromArgb(68, 86, 96);
|
|
chartControl3.BackColor = Color.FromArgb(68, 86, 96);
|
|
#endregion
|
|
}
|
|
|
|
|
|
#region 控件随窗体变大的类
|
|
public class CtrlAutoSize
|
|
{
|
|
System.Windows.Forms.Form thisForm;
|
|
private float x, y;
|
|
float newx, newy;
|
|
|
|
public CtrlAutoSize(System.Windows.Forms.Form form)
|
|
{
|
|
thisForm = form;
|
|
x = thisForm.Width;
|
|
y = thisForm.Height;
|
|
}
|
|
|
|
public void setTag(Control cons)
|
|
{
|
|
|
|
foreach (Control con in cons.Controls)
|
|
{
|
|
con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
|
|
if (con.Controls.Count > 0)
|
|
{
|
|
setTag(con);
|
|
}
|
|
}
|
|
}
|
|
public void setControls(Control cons)
|
|
{
|
|
newx = cons.Width / x;
|
|
newy = cons.Height / y;
|
|
foreach (Control con in cons.Controls)
|
|
{
|
|
string[] mytag = con.Tag.ToString().Split(new char[] { (':') });
|
|
float a = Convert.ToSingle(mytag[0]) * newx;
|
|
con.Width = (int)a;
|
|
a = Convert.ToSingle(mytag[1]) * newy;
|
|
con.Height = (int)a;
|
|
a = Convert.ToSingle(mytag[2]) * newx;
|
|
con.Left = (int)a;
|
|
a = Convert.ToSingle(mytag[3]) * newy;
|
|
con.Top = (int)a;
|
|
Single currentSize = Convert.ToSingle(mytag[4]) * newy;
|
|
con.Font = new System.Drawing.Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
|
|
if (con.Controls.Count > 0)
|
|
{
|
|
setControls(con);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void label2_Resize(object sender, EventArgs e)
|
|
{
|
|
autosize.setControls(this);
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
this.label9.Text = DateTime.Now.ToString();
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
|
|
private DataTable CreateData()
|
|
{
|
|
DataTable dt = new DataTable();
|
|
dt.Columns.Add(new DataColumn("类型"));
|
|
dt.Columns.Add(new DataColumn("2005-1月", typeof(decimal)));
|
|
dt.Columns.Add(new DataColumn("2005-2月", typeof(decimal)));
|
|
dt.Columns.Add(new DataColumn("2005-3月", typeof(decimal)));
|
|
dt.Columns.Add(new DataColumn("2005-4月", typeof(decimal)));
|
|
dt.Columns.Add(new DataColumn("2005-5月", typeof(decimal)));
|
|
dt.Columns.Add(new DataColumn("2005-6月", typeof(decimal)));
|
|
|
|
dt.Rows.Add(new object[] { "员工人数", 437, 437, 414, 397, 387, 378 });
|
|
dt.Rows.Add(new object[] { "人均月薪", 3964, 3961, 3979, 3974, 3967, 3972 });
|
|
dt.Rows.Add(new object[] { "成本TEU", 3104, 1339, 3595.8, 3154.5, 2499.8, 3026 });
|
|
dt.Rows.Add(new object[] { "人均生产率", 7.1, 3.06, 8.69, 7.95, 6.46, 8.01 });
|
|
dt.Rows.Add(new object[] { "占2005年3月人数比例", 1.06, 1.06, 1, 0.96, 0.93, 0.91 });
|
|
|
|
return dt;
|
|
}
|
|
|
|
private void CreatChart(DataTable dt)
|
|
{
|
|
chartControl1.Series.Clear();
|
|
chartControl1.Legend.BackColor = Color.FromArgb(68, 86, 96);
|
|
chartControl1.Legend.Border.Visible = false;
|
|
|
|
|
|
|
|
// 柱状图里的第一个柱
|
|
Series Series1 = CreateSeries1("员工人数", ViewType.Pie, dt, 0);
|
|
|
|
|
|
Series1.Label.BackColor = Color.FromArgb(47, 46, 42);
|
|
Series1.Label.Border.Visible = false;
|
|
//Series Series1 = new Series("员工人数", ViewType.Bar);
|
|
Series1.DataSource = dt;
|
|
Series1.ArgumentScaleType = ScaleType.Qualitative;
|
|
//Series1.ArgumentDataMember = "2005-1月";
|
|
// 以哪个字段进行显示
|
|
Series1.View.Color = Color.Yellow;
|
|
Series1.ValueScaleType = ScaleType.Numerical;
|
|
|
|
// 柱状图里的柱的取值字段
|
|
Series1.ValueDataMembers[0] = "2005-1月";
|
|
Series1.ArgumentDataMember = "类型";
|
|
Series1.LegendPointOptions.PointView = PointView.Argument;
|
|
//SetPiePercentage(Series1);
|
|
|
|
// 柱状图里的第二柱
|
|
//Series Series2 = CreateSeries2("人均月薪", ViewType.Pie, dt, 1);
|
|
////Series Series2 = new Series("", ViewType.Bar);
|
|
//Series2.DataSource = dt;
|
|
//Series2.View.Color = Color.Lime;
|
|
|
|
//Series2.ArgumentScaleType = ScaleType.Qualitative;
|
|
////Series2.Vi = ;
|
|
////Series2.ArgumentDataMember = "2005-2月";
|
|
//Series2.ValueScaleType = ScaleType.Numerical;
|
|
//Series2.Label.LineVisible = true;
|
|
//Series2.ValueDataMembers.AddRange(new string[] { "2005-2月" });
|
|
chartControl1.Series.Add(Series1);
|
|
//chartControl1.Series.Add(Series2);
|
|
chartControl1.Legend.BackColor = Color.FromArgb(47, 46, 42);
|
|
chartControl1.Legend.Border.Visible = false;
|
|
|
|
}
|
|
|
|
//public void SetPiePercentage(this Series series)
|
|
//{
|
|
// if (series.View is PieSeriesView)
|
|
// {
|
|
// ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent = true;
|
|
// ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
|
|
// ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision = 0;
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
private void CreatChart2(DataTable dt)
|
|
{
|
|
chartControl2.Series.Clear();
|
|
chartControl2.Legend.BackColor = Color.FromArgb(68, 86, 96);
|
|
chartControl2.Legend.Border.Visible = false;
|
|
|
|
|
|
// 柱状图里的第一个柱
|
|
Series Series1 = CreateSeries2("员工人数", ViewType.Bar, dt, 0);
|
|
BarSeriesView sv1 = (BarSeriesView)Series1.View;
|
|
sv1.FillStyle.FillMode = FillMode.Solid;
|
|
//Series Series1 = new Series("员工人数", ViewType.Bar);
|
|
Series1.DataSource = dt;
|
|
Series1.ArgumentScaleType = ScaleType.Qualitative;
|
|
|
|
//Series1.ArgumentDataMember = "2005-1月";
|
|
// 以哪个字段进行显示
|
|
Series1.View.Color = Color.Yellow;
|
|
Series1.ValueScaleType = ScaleType.Numerical;
|
|
|
|
// 柱状图里的柱的取值字段
|
|
Series1.ValueDataMembers.AddRange(new string[] { "2005-1月" });
|
|
|
|
// 柱状图里的第二柱
|
|
Series Series2 = CreateSeries2("人均月薪", ViewType.Bar, dt, 1);
|
|
//Series Series2 = new Series("", ViewType.Bar);
|
|
Series2.DataSource = dt;
|
|
Series2.View.Color = Color.Lime;
|
|
|
|
Series2.ArgumentScaleType = ScaleType.Qualitative;
|
|
//Series2.Vi = ;
|
|
//Series2.ArgumentDataMember = "2005-2月";
|
|
Series2.ValueScaleType = ScaleType.Numerical;
|
|
Series2.Label.LineVisible = true;
|
|
Series2.ValueDataMembers.AddRange(new string[] { "2005-2月" });
|
|
chartControl2.Series.Add(Series1);
|
|
chartControl2.Series.Add(Series2);
|
|
XYDiagram diagram = (XYDiagram)chartControl2.Diagram;
|
|
diagram.DefaultPane.BackColor = Color.FromArgb(68, 86, 96);
|
|
}
|
|
|
|
private void CreatChart3(DataTable dt)
|
|
{
|
|
chartControl3.Series.Clear();
|
|
chartControl3.Legend.BackColor = Color.FromArgb(68, 86, 96);
|
|
chartControl3.Legend.Border.Visible = false;
|
|
|
|
|
|
// 柱状图里的第一个柱
|
|
Series Series1 = CreateSeries2("员工人数", ViewType.Bar, dt, 0);
|
|
|
|
//Series Series1 = new Series("员工人数", ViewType.Bar);
|
|
Series1.DataSource = dt;
|
|
Series1.ArgumentScaleType = ScaleType.Qualitative;
|
|
//Series1.ArgumentDataMember = "2005-1月";
|
|
// 以哪个字段进行显示
|
|
Series1.View.Color = Color.Yellow;
|
|
Series1.ValueScaleType = ScaleType.Numerical;
|
|
|
|
// 柱状图里的柱的取值字段
|
|
Series1.ValueDataMembers.AddRange(new string[] { "2005-1月" });
|
|
|
|
// 柱状图里的第二柱
|
|
Series Series2 = CreateSeries2("人均月薪", ViewType.Bar, dt, 1);
|
|
//Series Series2 = new Series("", ViewType.Bar);
|
|
Series2.DataSource = dt;
|
|
Series2.View.Color = Color.Lime;
|
|
Series2.Label.TextColor = Color.Yellow;
|
|
Series2.ArgumentScaleType = ScaleType.Qualitative;
|
|
//Series2.ArgumentDataMember = "2005-2月";
|
|
Series2.ValueScaleType = ScaleType.Numerical;
|
|
Series2.ValueDataMembers.AddRange(new string[] { "2005-2月" });
|
|
chartControl3.Series.Add(Series1);
|
|
chartControl3.Series.Add(Series2);
|
|
XYDiagram diagram = (XYDiagram)chartControl3.Diagram;
|
|
diagram.DefaultPane.BackColor = Color.FromArgb(68, 86, 96);
|
|
}
|
|
//创建饼状图对象
|
|
private Series CreateSeries1(string caption, ViewType viewType, DataTable dt, int rowIndex)
|
|
{
|
|
Series series = new Series(caption, viewType);
|
|
for (int i = 1; i < dt.Columns.Count; i++)
|
|
{
|
|
string argument = dt.Columns[i].ColumnName;//参数名称
|
|
decimal value = (decimal)dt.Rows[rowIndex][i];//参数值
|
|
series.Points.Add(new SeriesPoint(argument, value));
|
|
}
|
|
return series;
|
|
}
|
|
//创建柱形图对象
|
|
private Series CreateSeries2(string caption, ViewType viewType, DataTable dt, int rowIndex)
|
|
{
|
|
Series series = new Series(caption, viewType);
|
|
for (int i = 1; i < dt.Columns.Count; i++)
|
|
{
|
|
string argument = dt.Columns[i].ColumnName;//参数名称
|
|
decimal value = (decimal)dt.Rows[rowIndex][i];//参数值
|
|
series.Points.Add(new SeriesPoint(argument, value));
|
|
}
|
|
BarSeriesView sv1 = (BarSeriesView)series.View;
|
|
sv1.FillStyle.FillMode = FillMode.Solid;
|
|
sv1.BarWidth = 0.5;
|
|
//柱形上的标签
|
|
series.LabelsVisibility = DefaultBoolean.True;
|
|
series.Label.Border.Visible = false;
|
|
series.Label.BackColor = Color.FromArgb(68, 86, 96);
|
|
series.Label.TextColor = Color.White;
|
|
series.Label.LineVisible = false;
|
|
series.Label.LineLength = 4;
|
|
return series;
|
|
}
|
|
|
|
private void FormWatch2_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
}
|