画柱状图方法收集
1
、立体感的柱状图
2
3
——这是在网上陶下来的漂亮代码
4
5
1<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
6
2
7
3<!--[if !mso]>
8
4
9
5<style>
10
6
11
7v\:* { behavior: url(#default#VML) }
12
8
13
9o\:* { behavior: url(#default#VML) }
14
10
15
11.shape { behavior: url(#default#VML) }
16
12
17
13</style>
18
14
19
15<![endif]-->
20
16
21
17<HEAD>
22
18
23
19<TITLE>柱状图形报表样列</TITLE>
24
20
25
21<SCRIPT LANGUAGE="JavaScript">
26
22
27
23//addPole 增加一个柱状图
28
24
29
25//left 与窗口左边的距离
30
26
31
27//width 宽度
32
28
33
29//height 高度
34
30
35
31//zindex 层高度
36
32
37
33//fillcolor 主色
38
34
39
35//color 渐变色
40
36
41
37//type 默认为竖,1为横
42
38
43
39function addPole(left,top,width,height,zindex,fillcolor,color,type){
44
40
45
41 top=top-height;
46
42
47
43 var a="";
48
44
49
45 if(type==1){
50
46
51
47 a="angle='-90' focus='100%'";
52
48
53
49 }
54
50
55
51 var html="<v:rect style='position:absolute;";
56
52
57
53 html=html+"left:"+left+"px;";
58
54
59
55 html=html+"top:"+top+"px;";
60
56
61
57 html=html+"width:"+width+"px;";
62
58
63
59 html=html+"height:"+height+"px;";
64
60
65
61 html=html+"z-index:"+zindex+"'";
66
62
67
63 html=html+"fillcolor='"+fillcolor+"'>";
68
64
69
65 html=html+"<v:fill color2='"+color+"'";
70
66
71
67 html=html+" rotate='t' "+a+" type='gradient'/><o:extrusion v:ext='view' backdepth='20pt' ";
72
68
73
69 html=html+"color='"+fillcolor+"' on='t'/></v:rect>";
74
70
75
71 document.write(html);
76
72
77
73}
78
74
79
75
80
76
81
77//left 与窗口左边的距离
82
78
83
79//width 宽度
84
80
85
81//height 高度
86
82
87
83//zindex 立体高度
88
84
89
85//fillcolor 主色
90
86
91
87function addBackground(left,top,width,height,zindex,fillcolor){
92
88
93
89 top=top-height;
94
90
95
91 var html="<v:rect style='position:absolute;left:"+left+"px;";
96
92
97
93 html=html+"top:"+top+"px;";
98
94
99
95 html=html+"width:"+width+"px;";
100
96
101
97 html=html+"height:"+height+"px;";
102
98
103
99 html=html+"z-index:"+zindex+"'";
104
100
105
101 html=html+"fillcolor='"+fillcolor+"'";
106
102
107
103 html=html+" stroked='f'><v:fill rotate='t' angle='-45' focus='100%' type='gradient'/></v:rect>";
108
104
109
105 document.write(html);
110
106
111
107}
112
108
113
109
114
110
115
111function addLine(zindex,from,to,color){
116
112
117
113 var html="<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:"+zindex+"'";
118
114
119
115 html=html+" from='"+from+"' to='"+to+"' strokecolor='"+color+"'/>"
120
116
121
117 document.write(html);
122
118
123
119}
124
120
125
121
126
122
127
123function addText(left,top,width,height,zindex,value,fontsize){
128
124
129
125 top=top-height;
130
126
131
127 var html="<v:shape style='position:absolute;left:"+left+"px;";
132
128
133
129 html=html+"top:"+top+"px;";
134
130
135
131 html=html+"width:"+width+"px;";
136
132
137
133 html=html+"height:"+height+"px;";
138
134
139
135 html=html+"z-index:"+zindex+"'>";
140
136
141
137 html=html+"<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td";
142
138
143
139 html=html+" style='FONT-SIZE:"+fontsize+"' align='center'>"+value+"</td></tr></table></v:textbox></v:shape>";
144
140
145
141 document.write(html);
146
142
147
143}
148
144
149
145
150
146
151
147function addGround(left,top,width,height,zindex,fillcolor,linecolor1,linecolor2,offset,level,min,leftoffset,textwidth,textheight,fontsize){
152
148
153
149 addBackground(left,top,width,height,zindex,fillcolor);
154
150
155
151 addLine(zindex,left+"px,"+top+"px",((left-0)+(width-0))+"px,"+top+"px",linecolor1);
156
152
157
153 addLine(zindex,left+"px,"+top+"px",left+"px,"+(top-height)+"px",linecolor1);
158
154
159
155 addLine(zindex,((left-0)+(offset-0))+"px,"+(top-offset)+"px",((left-0)+(width-0))+"px,"+(top-offset)+"px",linecolor2);
160
156
161
157 addLine(zindex,((left-0)+(offset-0))+"px,"+(top-offset)+"px",((left-0)+(offset-0))+"px,"+(top-height)+"px",linecolor2);
162
158
163
159 addLine(zindex,left+"px,"+(top-offset)+"px",((left-0)+(offset-0))+"px,"+top+"px",linecolor2);
164
160
165
161 for(var i=1;i<level;i++){
166
162
167
163 addLine(zindex,left+"px,"+(top-offset-(height*i)/level)+"px",((left-0)+(offset-0))+"px,"+(top-(height*i)/level)+"px",linecolor2);
168
164
169
165 addLine(zindex,(left-leftoffset)+"px,"+(top-(height*i)/level)+"px",left+"px,"+(top-(height*i)/level)+"px",linecolor1);
170
166
171
167 addText(left-textwidth,(top-(height*i)/level)+(textheight-0)+2,textwidth,textheight,"-1",i*min,fontsize)
172
168
173
169 addLine(zindex,((left-0)+(offset-0))+"px,"+(top-offset-(height*i)/level)+"px",((left-0)+(width-0))+"px,"+(top-offset-(height*i)/level)+"px",linecolor2);
174
170
175
171 }
176
172
177
173 addLine(zindex,(left-leftoffset)+"px,"+(top-(height*level)/level)+"px",left+"px,"+(top-(height*level)/level)+"px",linecolor1);
178
174
179
175 addText(left-textwidth,(top-(height*level)/level)+(textheight-0)+2,textwidth,textheight,"-1",level*min,fontsize)
180
176
181
177}
182
178
183
179
184
180
185
181function addEPole(left,top,width,height,zindex,fillcolor,color,textwidth,textheight,value1,value2,fontsize){
186
182
187
183 addText(left-textwidth/2+width/2,top-height-10,textwidth,textheight,zindex,value1,fontsize);
188
184
189
185 addText(left-textwidth/2+width/2,(top-0)+(textheight-0),textwidth,textheight,zindex,value2,fontsize);
190
186
191
187 addPole(left,top,width,height,zindex,fillcolor,color)
192
188
193
189}
194
190
195
191</SCRIPT>
196
192
197
193</HEAD>
198
194
199
195
200
196
201
197<BODY>
202
198
203
199<div>
204
200
205
201<SCRIPT LANGUAGE="JavaScript">
206
202
207
203<!--
208
204
209
205
210
206
211
207addEPole("180","400","30","150","1","#3300FF","#66FFFF","80","18","300","1月份","9pt");
212
208
213
209addEPole("230","400","30","300","1","#FF0000","#99FFFF","80","18","600","2月份","9pt");
214
210
215
211addEPole("280","400","30","200","1","#33CC00","#99FFFF","80","18","400","3月份","9pt");
216
212
217
213addEPole("330","400","30","100","1","#FF0099","#99FFFF","80","18","200","4月份","9pt");
218
214
219
215addEPole("380","400","30","50","1","#660000","#99FFFF","80","18","100","5月份","9pt");
220
216
221
217addEPole("430","400","30","20","1","#FFFF00","#99FFFF","80","18","40","6月份","9pt");
222
218
223
219addEPole("480","400","30","180","1","#330066","#99FFFF","80","18","360","7月份","9pt");
224
220
225
221addEPole("530","400","30","120","1","#CC6633","#99FFFF","80","18","240","8月份","9pt");
226
222
227
223addEPole("580","400","30","80","1","#9933FF","#99FFFF","80","18","160","9月份","9pt");
228
224
229
225addGround("160","400","460","300","-1","#33CCFF","#000000","#6699CC","10","6","100","20","40","18","9pt")
230
226
231
227//-->
232
228
233
229</SCRIPT>
234
230
235
231</div>
236
232
237
233</body>
238
234
239
235</html>
240

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

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

效果图如下:
其中方法调用,想知道每个参数的详细信息
addEPole("580","400","30","80","1","#9933FF","#99FFFF","80","18","160","9月份","
参数含义包括上边距离,左边距,以及高宽,以及XY上的内容 。以及颜色,柱体的宽度等等信息。
addGround("160","400","460","300","-1","#33CCFF","#000000","#6699CC","10","6","100","20","40","18","
定义了范围大小以及6个刻度,每个100,还包括字体大小,刻度线颜色,以及内部线条颜色,以及渐变色等等含义。
文章转自以下地址,在此感谢作者的分享
http://www.blogjava.net/JAVA-HE/archive/2007/05/08/115813.html