ucEquipSpLineColumn.cs
6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using MyClassLib;
namespace MyControlLib
{
public partial class ucEquipSpLineColumn : UserControl
{
public ucEquipSpLineColumn()
{
InitializeComponent();
}
/// <summary>
/// 绘制柱状图和双曲线图
/// </summary>
/// <param name="title">标题</param>
/// <param name="connectstring">连接字符串</param>
/// <param name="sql">SQL语句 Format格式.select var1 as colName,var2 as columnValue, var3 as splineValue from TableName </param>
/// <param name="columuColor">柱状图的颜色</param>
/// <param name="SplineColor">曲线的颜色</param>
public void DrawColumnSpline(string title, string connectstring, string sql, Color columuColor, Color SplineColor)
{
try
{
//chart1.Series.Clear();
if (sql.IndexOf("colName") < 0) { throw new ArgumentException(string.Format("{0}参数中无colName", sql)); }
if (sql.IndexOf("columnValue") < 0) { throw new ArgumentException(string.Format("{0}参数中无columValue", sql)); }
if (sql.IndexOf("splineValue") < 0) { throw new ArgumentException(string.Format("{0}参数中无splineValue", sql)); }
SqlConnection conn = new SqlConnection(connectstring);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
chart1.Series.Clear();
chart1.DataSource = cmd;
//标题
chart1.Titles.Clear();
chart1.Titles.Add(title);
Series ser1 = new Series();
chart1.Series.Add(ser1);
ser1.XValueMember = "colName";
ser1.YValueMembers = "columnValue";
ser1.ChartType = SeriesChartType.Column;
ser1.IsValueShownAsLabel = true; //是否显示数据
ser1.IsVisibleInLegend = false; //是否显示数据说明
ser1.MarkerStyle = MarkerStyle.Circle; //线条上的数据点标志类型
ser1.MarkerSize = 6; //标志大小
ser1.Color = columuColor;
ser1.LegendToolTip = "#Val";
Series ser2 = new Series();
chart1.Series.Add(ser2);
ser2.XValueMember = "colName";
ser2.YValueMembers = "splineValue";
ser2.ChartType = SeriesChartType.Spline;
ser2.IsValueShownAsLabel = true; //是否显示数据
ser2.IsVisibleInLegend = false; //是否显示数据说明
ser2.MarkerStyle = MarkerStyle.Circle; //线条上的数据点标志类型
ser2.MarkerSize = 6; //标志大小
ser2.Color = SplineColor;
ser2.BorderWidth = 3;
ser2.LegendToolTip = "#val{D}";
conn.Close();
chart1.DataBind();
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("DrawCloumnSpline", ex);
}
}
/// <summary>
/// 绘制柱状图
/// </summary>
/// <param name="title">标题</param>
/// <param name="connectstring">连接字符串</param>
/// <param name="sql">SQL语句Format格式.select var1 as colName,var2 , var3 ,... from TableName </param>
public void DrawColumn(string title,string connectstring, string sql)
{
try
{
if (sql.IndexOf("colName") < 0) { throw new ArgumentException(string.Format("{0}参数中无colName", sql)); }
//chart1.Series.Clear();
chart1.Series.Clear();
//标题
chart1.Titles.Clear();
chart1.Titles.Add(title);
SqlConnection conn = new SqlConnection(connectstring);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader read = cmd.ExecuteReader();
chart1.DataBindTable(read, "colName");
read.Close();
conn.Close();
chart1.Series[0].ChartType = SeriesChartType.Column;
chart1.Series[0].IsValueShownAsLabel = true; //是否显示数据
chart1.Series[0].IsVisibleInLegend = false; //是否显示数据说明
chart1.Series[0].MarkerStyle = MarkerStyle.Circle; //线条上的数据点标志类型
chart1.Series[0].MarkerSize = 6; //标志大小
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("DrawCloumn", ex);
}
}
/// <summary>
/// 绘制曲线图
/// </summary>
/// <param name="title">标题</param>
/// <param name="connectstring">连接字符串</param>
/// <param name="sql">SQL语句Format格式.select var1 as colName,var2 , var3 ,... from TableName </param>
public void DrawSpline(string title, string connectstring, string sql)
{
try
{
if (sql.IndexOf("colName") < 0) { throw new ArgumentException(string.Format("{0}参数中无colName", sql)); }
//chart1.Series.Clear();
chart1.Series.Clear();
//标题
chart1.Titles.Clear();
chart1.Titles.Add(title);
SqlConnection conn = new SqlConnection(connectstring);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader read = cmd.ExecuteReader();
chart1.DataBindTable(read, "colName");
read.Close();
conn.Close();
chart1.Series[0].ChartType = SeriesChartType.Spline;
chart1.Series[0].IsValueShownAsLabel = true; //是否显示数据
chart1.Series[0].IsVisibleInLegend = false; //是否显示数据说明
chart1.Series[0].MarkerStyle = MarkerStyle.Circle; //线条上的数据点标志类型
chart1.Series[0].MarkerSize = 6; //标志大小
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("DrawSpline", ex);
}
}
}
}