结合Bindows生成折线图[代码]
还是用mshtml的那个项目中……
Bindows还不是很熟,使用的是ChartTest.xml Sample
用字符串构造的,高手勿笑
代码如下:
1
/// <summary>
2
/// 生成当前系统时间TimeStamp,作为输出文件名的一部分使用
3
/// </summary>
4
/// <returns>格式如"20050421123120"的字符串</returns>
5
private string CurTimeStamp()
6
{
7
System.Text.StringBuilder sbCN = new System.Text.StringBuilder(20);
8
9
sbCN.Append(System.DateTime.Now.ToShortDateString());
10
11
sbCN.Replace("-", "");
12
13
sbCN.Append(System.DateTime.Now.ToShortTimeString());
14
15
sbCN.Replace(":", "");
16
17
sbCN.Append(System.DateTime.Now.Millisecond.ToString());
18
19
return sbCN.ToString();
20
}
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
/// <summary>
2
/// 折线图,要求视图的第一个字段为横坐标的值(Series),从中间字段开始的其余字段为指标的值(Categories)
3
/// </summary>
4
/// <param name="标题">Bidows窗体显示的标题</param>
5
/// <param name="文件名">保存的文件名</param>
6
/// <param name="宽度">Bindows窗体的宽度</param>
7
/// <param name="高度">Bindows窗体的高度</param>
8
/// <param name="视图">使用的视图</param>
9
/// <param name="中间字段">构造的视图可能要包含多余的字段,设定此值介定</param>
10
/// <param name="查询条件">视图的筛选条件</param>
11
private void LineChart(string 标题, string 文件名, int 宽度, int 高度, string 视图, int 中间字段, string 查询条件)
12
{
13
//当前TimeStamp
14
string sbCN = this.CurTimeStamp();
15
16
mshtml.IHTMLWindow2 win2 = this.doc.parentWindow;
17
18
System.Text.StringBuilder sbContent = new System.Text.StringBuilder(100);
19
20
sbContent.Append("<?xml version=\"1.0\" ?>\n");
21
22
sbContent.Append("<application>\n");
23
24
sbContent.Append("<window caption=\"" + 标题 + "\" width=\"" + 宽度.ToString() + "\" height=\"" + 高度.ToString() + "\" centered=\"true\"/>\n");
25
26
sbContent.Append("<resources>\n");
27
28
sbContent.Append("<script>\n");
29
30
sbContent.Append("<![CDATA[\n");
31
32
sbContent.Append("function " + 文件名 + sbCN.ToString() + "() {\n");
33
34
sbContent.Append("var win = application.getWindow();\n");
35
36
sbContent.Append("var g = new BiGraph;\n");
37
38
string strSQL = "SELECT * FROM " + 视图 + " WHERE " + 查询条件;
39
40
System.Data.DataSet dsResult = HEWin.Sys.sysDb.GetDataSetBySql(strSQL, "Result");
41
42
sbContent.Append("g.setCategories([\n");
43
44
//Series
45
for (int loop = 0; loop < dsResult.Tables["Result"].Rows.Count; loop ++)
46
sbContent.Append("new BiChartCategory(g, \"c" + System.Convert.ToString(loop + 1) + "\", \"" + dsResult.Tables["Result"].Rows[loop][0].ToString() + "\"),");
47
48
sbContent.Remove(sbContent.Length - 1, 1);
49
50
sbContent.Append("]);\n");
51
52
strSQL = "SELECT syscolumns.name, syscolumns.colid FROM syscolumns INNER JOIN sysobjects ON syscolumns.id = sysobjects.id WHERE (sysobjects.name = N'" + 视图 + "') ORDER BY syscolumns.colid";
53
54
System.Data.DataSet dsTable = HEWin.Sys.sysDb.GetDataSetBySql(strSQL, "Table");
55
56
int intStart = 1;
57
58
//Categories
59
for (int i = 中间字段; i < dsTable.Tables["Table"].Rows.Count; i ++)
60
{
61
sbContent.Append("g.addSeries( new BiChartSeries(g, \"s" + intStart.ToString() + "\", \"" + dsTable.Tables["Table"].Rows[i]["name"].ToString() + "\", [");
62
63
for (int j = 0; j < dsResult.Tables["Result"].Rows.Count; j ++)
64
sbContent.Append(dsResult.Tables["Result"].Rows[j][i].ToString() + ",");
65
66
sbContent.Remove(sbContent.Length - 1, 1);
67
68
sbContent.Append("]) );\n");
69
70
intStart ++;
71
}
72
73
sbContent.Append("win.add(g);\n");
74
75
sbContent.Append("g.update();\n");
76
77
sbContent.Append("g.setLocation(0, 0);\n");
78
79
sbContent.Append("g.setRight(0);\n");
80
81
sbContent.Append("g.setBottom(0);\n");
82
83
sbContent.Append("}\n");
84
85
sbContent.Append(文件名 + sbCN + ".main = function () { new " + 文件名 + sbCN.ToString() + "; };\n");
86
87
sbContent.Append("]]>\n");
88
89
sbContent.Append("</script>\n");
90
91
sbContent.Append("</resources>\n");
92
93
sbContent.Append("</application>\n");
94
95
string strFileName = 文件名 + sbCN + ".xml";
96
97
string strRet = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"html\html\bindows\launcher\" + strFileName);
98
99
System.IO.StreamWriter swResult = new System.IO.StreamWriter(strRet, false, System.Text.Encoding.UTF8);
100
101
swResult.Write(sbContent.ToString());
102
103
swResult.Close();
104
105
win2.execScript("biExec('../html', '" + strFileName + "', false, 0, 'one', true);", "JavaScript");
106
107
win2 = null;
108
109
dsResult.Dispose();
110
111
}
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
Life is like a boat, and I'm at sea.
浙公网安备 33010602011771号