

1
public delegate string SetXColumnHandler(string ora_Str);
2
public class ChartHelper
3
{
4
public event SetXColumnHandler OnSetXColumn;
5
public string SetXColumn(string ora_str)
6
{
7
if (OnSetXColumn != null)
8
{
9
return OnSetXColumn(ora_str);
10
}
11
return ora_str;
12
}
13
14
public void Create(Chart chart, string title, DataTable table, string xColumn, string yColumn, string style, bool user3D)
15
{
16
chart.Palette = new Color[]
{ Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255),
17
Color.FromArgb(255, 125, 49), Color.FromArgb(125, 255, 49), Color.FromArgb(0, 255, 49) };
18
chart.Use3D = user3D;
19
SeriesCollection mySC = getRandomData(table, xColumn, yColumn);
20
if (string.IsNullOrEmpty(style) || style == "线形")
21
{
22
chart.Type = ChartType.Combo;
23
mySC = getRandomData2(table, xColumn, yColumn);
24
}
25
else if (style == "柱形")
26
{
27
chart.Type = ChartType.Combo;
28
}
29
else if (style == "金字塔")
30
{
31
chart.Type = ChartType.MultipleGrouped;
32
chart.DefaultSeries.Type = SeriesTypeMultiple.Pyramid;
33
}
34
else if (style == "圆锥")
35
{
36
chart.Type = ChartType.MultipleGrouped;
37
chart.DefaultSeries.Type = SeriesTypeMultiple.Cone;
38
}
39
chart.Title = title;
40
if (string.IsNullOrEmpty(style) || style == "线形")
41
{
42
chart.DefaultSeries.Type = SeriesType.Line;
43
}
44
45
chart.DefaultElement.ShowValue = true;
46
chart.PieLabelMode = PieLabelMode.Outside;
47
chart.ShadingEffectMode = ShadingEffectMode.Three;
48
chart.NoDataLabel.Text = "没有数据显示";
49
chart.SeriesCollection.Add(mySC);
50
}
51
public void Create(Chart chart, string title, List<DataTable> tables, List<DateTime> dates, string xColumn, string yColumn, string style, bool user3D,string targetUrl)
52
{
53
chart.Palette = new Color[]
{ Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255),
54
Color.FromArgb(255, 125, 49), Color.FromArgb(125, 255, 49), Color.FromArgb(0, 255, 49) };
55
chart.Use3D = user3D;
56
chart.Type = ChartType.Combo;
57
chart.Title = title;
58
chart.DefaultSeries.Type = SeriesTypeMultiple.Pyramid;
59
SeriesCollection SC = new SeriesCollection();
60
61
for (int i = 0; i < dates.Count; i++)
62
{
63
string dtStr = dates[i].ToString("yyyy-MM-dd");
64
Series s = new Series(dtStr);
65
foreach (DataRow r in tables[i].Rows)
66
{
67
Element e = new Element(r[xColumn].ToString());
68
e.URLTarget = "_self";
69
e.LegendEntry.URL = string.Concat(targetUrl, dtStr);
70
e.LegendEntry.URLTarget = "_self";
71
e.URL = string.Concat(targetUrl,dtStr);
72
e.YValue = Convert.ToDouble(r[yColumn]);
73
s.Elements.Add(e);
74
SC.Add(s);
75
}
76
}
77
chart.DefaultElement.ShowValue = true;
78
if (string.IsNullOrEmpty(style) || style == "线形")
79
{
80
chart.DefaultSeries.Type = SeriesType.Line;
81
}
82
chart.PieLabelMode = PieLabelMode.Outside;
83
chart.ShadingEffectMode = ShadingEffectMode.Three;
84
chart.NoDataLabel.Text = "没有数据显示";
85
chart.SeriesCollection.Add(SC);
86
87
}
88
SeriesCollection getRandomData(DataTable table, string x,string y)
89
{
90
SeriesCollection SC = new SeriesCollection();
91
foreach (DataRow r in table.Rows)
92
{
93
Series s = new Series(r[x].ToString());
94
Element e = new Element(r[x].ToString());
95
e.YValue = Convert.ToDouble(r[y]);
96
s.Elements.Add(e);
97
SC.Add(s);
98
}
99
return SC;
100
}
101
SeriesCollection getRandomData2(DataTable table, string x, string y)
102
{
103
SeriesCollection SC = new SeriesCollection();
104
Series s = new Series();
105
foreach (DataRow r in table.Rows)
106
{
107
Element e = new Element(r[x].ToString());
108
e.YValue = Convert.ToDouble(r[y]);
109
s.Elements.Add(e);
110
}
111
SC.Add(s);
112
return SC;
113
}
114
115
public void Pie(dotnetCHARTING.Chart chart, int width, int height, string title,DataTable table, string xColumn, string yColumn)
116
{
117
118
SeriesCollection SC = new SeriesCollection();
119
Series s = new Series("");
120
DataView view = new DataView(table);
121
view.Sort = yColumn + " desc";
122
int index = 0;
123
DataTable table2 = view.ToTable();
124
Element otherE = new Element("其他");
125
126
bool other = false;
127
double otherSum = 0;
128
foreach (DataRow row in table2.Rows)
129
{
130
if (index > 9)
131
{
132
otherSum += Convert.ToDouble(row[yColumn].ToString());
133
otherE.LabelTemplate = "%PercentOfTotal";
134
other = true;
135
continue;
136
}
137
string telType = row[xColumn].ToString();
138
telType = SetXColumn(telType);
139
Element e = new Element(telType);
140
e.LabelTemplate = "%PercentOfTotal";
141
142
e.YValue = Convert.ToDouble(row[yColumn].ToString());
143
s.Elements.Add(e);
144
index++;
145
}
146
if (other)
147
{
148
s.Elements.Add(otherE);
149
}
150
chart.TitleBox.Position = TitleBoxPosition.FullWithLegend;
151
otherE.YValue = otherSum;
152
SC.Add(s);
153
chart.TempDirectory = "temp";
154
chart.Use3D = false;
155
chart.DefaultAxis.FormatString = "N";
156
chart.DefaultAxis.CultureName = "zh-CN";
157
chart.Palette = new Color[]
{ Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255)
158
,Color.FromArgb(255, 156, 255),Color.FromArgb(0, 156, 0),Color.FromArgb(0, 156, 99),Color.FromArgb(0, 99, 255),Color.FromArgb(99, 156, 255),
159
Color.FromArgb(0, 0, 99),Color.FromArgb(0, 156, 126)};
160
chart.DefaultElement.SmartLabel.AutoWrap = true;
161
chart.Type = ChartType.Pies;
162
chart.Size = width + "x" + height;
163
chart.DefaultElement.SmartLabel.Text = "";
164
chart.Title = title;
165
chart.DefaultElement.ShowValue = true;
166
chart.PieLabelMode = PieLabelMode.Outside;
167
chart.ShadingEffectMode = ShadingEffectMode.Three;
168
chart.DefaultElement.SmartLabel.AutoWrap = true;
169
chart.NoDataLabel.Text = "没有数据显示";
170
chart.SeriesCollection.Add(SC);
171
}
172
public void Create(dotnetCHARTING.Chart chart, string title, DataTable table, string xColumn, string yColumn, string style, int displayNum)
173
{
174
SeriesCollection SC = new SeriesCollection();
175
DataView view = new DataView(table);
176
view.Sort = yColumn + " desc";
177
int index = 0;
178
DataTable table2 = view.ToTable();
179
Element otherE = new Element("其他");
180
bool other = false;
181
double otherSum = 0;
182
Color c = Color.FromArgb(49, 255, 49);
183
Random r = new Random(255);
184
Color c1 = Color.FromArgb(255, 49, 255);
185
List<Color> list = new List<Color>();
186
list.Add(c);
187
list.Add(c1);
188
for (int i = 0; i < displayNum; i++)
189
{
190
Color cc = Color.FromArgb((c.A + r.Next(10000)) % 255, (c.B + r.Next(456)) % 255, (c.G + r.Next(1027)) % 100);
191
list.Add(cc);
192
}
193
foreach (DataRow row in table2.Rows)
194
{
195
Series s = new Series("");
196
if (index > displayNum - 2)
197
{
198
otherSum += Convert.ToDouble(row[yColumn].ToString());
199
otherE.LabelTemplate = "%PercentOfTotal";
200
other = true;
201
continue;
202
}
203
204
string telType = row[xColumn].ToString();
205
telType = SetXColumn(telType);
206
s.Name = telType;
207
Element e = new Element(telType);
208
e.LabelTemplate = "%PercentOfTotal";
209
e.SmartLabel.Text = telType;
210
211
212
e.YValue = Convert.ToDouble(row[yColumn].ToString());
213
s.Elements.Add(e);
214
index++;
215
SC.Add(s);
216
}
217
if (other)
218
{
219
Series s = new Series("其他");
220
s.Elements.Add(otherE);
221
SC.Add(s);
222
}
223
otherE.YValue = otherSum;
224
otherE.SmartLabel.Text = "其他";
225
226
chart.TempDirectory = "temp";
227
chart.Use3D = false;
228
chart.DefaultAxis.FormatString = "N";
229
chart.DefaultAxis.CultureName = "zh-CN";
230
chart.Palette = list.ToArray();
231
chart.DefaultElement.SmartLabel.AutoWrap = true;
232
if (string.IsNullOrEmpty(style) || style == "线形")
233
{
234
chart.Type = ChartType.Combo;
235
chart.DefaultSeries.Type = SeriesType.Line;
236
}
237
else if (style == "柱形")
238
{
239
chart.Type = ChartType.Combo;
240
}
241
else if (style == "横柱形")
242
{
243
chart.Type = ChartType.ComboHorizontal;
244
}
245
else if (style == "图片柱形")
246
{
247
chart.Type = ChartType.Combo;
248
chart.DefaultSeries.ImageBarTemplate = "ethernetcable";
249
}
250
else if (style == "雷达")
251
{
252
chart.Type = ChartType.Radar;
253
}
254
else if (style == "圆锥")
255
{
256
chart.Type = ChartType.MultipleGrouped;
257
chart.DefaultSeries.Type = SeriesTypeMultiple.Cone;
258
}
259
chart.DefaultElement.SmartLabel.Text = "";
260
chart.Title = title;
261
chart.DefaultElement.ShowValue = true;
262
chart.PieLabelMode = PieLabelMode.Outside;
263
chart.ShadingEffectMode = ShadingEffectMode.Three;
264
chart.DefaultElement.SmartLabel.AutoWrap = true;
265
chart.NoDataLabel.Text = "没有数据显示";
266
chart.SeriesCollection.Add(SC);
267
}
268
public void Pie2(dotnetCHARTING.Chart chart, string title, DataTable table, string xColumn, string yColumn,string style,int displayNum)
269
{
270
SeriesCollection SC = new SeriesCollection();
271
Series s = new Series("");
272
DataView view = new DataView(table);
273
view.Sort = yColumn + " desc";
274
int index = 0;
275
DataTable table2 = view.ToTable();
276
Element otherE = new Element("其他");
277
bool other = false;
278
double otherSum = 0;
279
Color c = Color.FromArgb(49, 255, 49);
280
Random r = new Random(255);
281
Color c1 = Color.FromArgb(255, 49, 255);
282
List<Color> list = new List<Color>();
283
list.Add(c);
284
list.Add(c1);
285
for (int i = 0; i < displayNum; i++)
286
{
287
Color cc = Color.FromArgb((c.A + r.Next(10000)) % 255, (c.B + r.Next(456)) % 255, (c.G + r.Next(1027)) % 100);
288
list.Add(cc);
289
}
290
foreach (DataRow row in table2.Rows)
291
{
292
if (index > displayNum - 2)
293
{
294
otherSum += Convert.ToDouble(row[yColumn].ToString());
295
otherE.LabelTemplate = "%PercentOfTotal";
296
other = true;
297
continue;
298
}
299
string telType = row[xColumn].ToString();
300
telType = SetXColumn(telType);
301
Element e = new Element(telType);
302
e.LabelTemplate = "%PercentOfTotal";
303
e.SmartLabel.Text = telType;
304
305
306
e.YValue = Convert.ToDouble(row[yColumn].ToString());
307
s.Elements.Add(e);
308
index++;
309
}
310
if (other)
311
{
312
s.Elements.Add(otherE);
313
}
314
otherE.YValue = otherSum;
315
otherE.SmartLabel.Text = "其他";
316
SC.Add(s);
317
chart.TempDirectory = "temp";
318
chart.Use3D = false;
319
chart.DefaultAxis.FormatString = "N";
320
chart.DefaultAxis.CultureName = "zh-CN";
321
chart.Palette = list.ToArray();
322
chart.DefaultElement.SmartLabel.AutoWrap = true;
323
if (style == "饼形")
324
{
325
chart.Type = ChartType.Pies;
326
}
327
else if (style == "柱形")
328
{
329
chart.Type = ChartType.Combo;
330
}
331
else if (style == "横柱形")
332
{
333
chart.Type = ChartType.ComboHorizontal;
334
}
335
else if (style == "图片柱形")
336
{
337
chart.Type = ChartType.Combo;
338
chart.DefaultSeries.ImageBarTemplate = "ethernetcable";
339
}
340
else if (style == "雷达")
341
{
342
chart.Type = ChartType.Radar;
343
}
344
else if (style == "圆锥")
345
{
346
chart.Type = ChartType.MultipleGrouped;
347
chart.DefaultSeries.Type = SeriesTypeMultiple.Cone;
348
}
349
chart.DefaultElement.SmartLabel.Text = "";
350
chart.Title = title;
351
chart.DefaultElement.ShowValue = true;
352
chart.PieLabelMode = PieLabelMode.Outside;
353
chart.ShadingEffectMode = ShadingEffectMode.Three;
354
chart.DefaultElement.SmartLabel.AutoWrap = true;
355
chart.NoDataLabel.Text = "没有数据显示";
356
chart.SeriesCollection.Add(SC);
357
}
358
public void Pie2(dotnetCHARTING.Chart chart, string title, DataTable table, string xColumn, string yColumn, string style, int displayNum, string targetUrl)
359
{
360
Pie2(chart, title, table, xColumn, yColumn, style, displayNum, targetUrl, "Jpg", "", false);
361
}
362
public void Pie2(dotnetCHARTING.Chart chart, string title, DataTable table,
363
string xColumn, string yColumn, string style,
364
int displayNum,string targetUrl,string format,
365
string legendBoxPos,bool user3d)
366
{
367
SeriesCollection SC = new SeriesCollection();
368
Series s = new Series("");
369
DataView view = new DataView(table);
370
view.Sort = yColumn + " desc";
371
int index = 0;
372
DataTable table2 = view.ToTable();
373
Element otherE = new Element("其他");
374
bool other = false;
375
double otherSum = 0;
376
Color c = Color.FromArgb(49, 255, 49);
377
Random r = new Random(255);
378
Color c1 = Color.FromArgb(255, 49, 255);
379
List<Color> list = new List<Color>();
380
list.Add(c);
381
list.Add(c1);
382
for (int i = 0; i < displayNum; i++)
383
{
384
Color cc = Color.FromArgb((c.A + r.Next(50000)) % 255, (c.B + r.Next(456)) % 255, (c.G + r.Next(1207)) % 100);
385
list.Add(cc);
386
}
387
if (legendBoxPos.ToLower() == "title")
388
{
389
chart.TitleBox.Position = TitleBoxPosition.FullWithLegend;
390
}
391
foreach (DataRow row in table2.Rows)
392
{
393
if (index > displayNum)
394
{
395
otherSum += Convert.ToDouble(row[yColumn].ToString());
396
otherE.LabelTemplate = "%Name: %PercentOfTotal";
397
other = true;
398
continue;
399
}
400
string telType = row[xColumn].ToString();
401
telType = SetXColumn(telType);
402
Element e = new Element(telType);
403
e.ToolTip = telType;
404
e.LabelTemplate = "%PercentOfTotal";
405
e.LegendEntry.HeaderMode = LegendEntryHeaderMode.RepeatOnEachColumn;
406
e.LegendEntry.SortOrder = 0;
407
if (!string.IsNullOrEmpty(targetUrl))
408
{
409
e.LegendEntry.URL = targetUrl + telType;
410
e.LegendEntry.URLTarget = "_self";
411
e.URL = targetUrl + telType;
412
e.URLTarget = "_self";
413
}
414
e.YValue = Convert.ToDouble(row[yColumn].ToString());
415
s.Elements.Add(e);
416
index++;
417
}
418
if (other)
419
{
420
s.Elements.Add(otherE);
421
}
422
otherE.YValue = otherSum;
423
otherE.SmartLabel.Text = "其他";
424
SC.Add(s);
425
chart.TempDirectory = "temp";
426
chart.Use3D = user3d;
427
chart.DefaultAxis.FormatString = "N";
428
chart.DefaultAxis.CultureName = "zh-CN";
429
chart.Palette = list.ToArray();
430
chart.DefaultElement.SmartLabel.AutoWrap = true;
431
if (style == "饼形")
432
{
433
chart.Type = ChartType.Pies;
434
}
435
else if (style == "柱形")
436
{
437
chart.Type = ChartType.Combo;
438
}
439
else if (style == "横柱形")
440
{
441
chart.Type = ChartType.ComboHorizontal;
442
}
443
else if (style == "图片柱形")
444
{
445
chart.Type = ChartType.Combo;
446
chart.DefaultSeries.ImageBarTemplate = "ethernetcable";
447
}
448
else if (style == "雷达")
449
{
450
chart.Type = ChartType.Radar;
451
}
452
else if (style == "圆锥")
453
{
454
chart.Type = ChartType.MultipleGrouped;
455
chart.DefaultSeries.Type = SeriesTypeMultiple.Cone;
456
}
457
chart.Title = title;
458
chart.PieLabelMode = PieLabelMode.Automatic;
459
chart.DefaultElement.ShowValue = true;
460
chart.ShadingEffectMode = ShadingEffectMode.Three;
461
chart.LegendBox.DefaultEntry.PaddingTop = 5;
462
switch (format)
463
{
464
case "Jpg":
465
{
466
chart.ImageFormat = ImageFormat.Jpg;
467
break;
468
}
469
case "Png":
470
{
471
chart.ImageFormat = ImageFormat.Png;
472
break;
473
}
474
case "Swf":
475
{
476
chart.ImageFormat = ImageFormat.Swf;
477
break;
478
}
479
}
480
chart.DefaultElement.SmartLabel.AutoWrap = true;
481
chart.NoDataLabel.Text = "没有数据显示";
482
chart.SeriesCollection.Add(SC);
483
}
484
485
486
public static void ComboHorizontal(dotnetCHARTING.Chart chart, int width, int height, string title, DataTable table, string xColumn, string yColumn)
487
{
488
SeriesCollection SC = new SeriesCollection();
489
Series s = new Series();
490
foreach (DataRow row in table.Rows)
491
{
492
string telType = row[xColumn].ToString();
493
Element e = new Element();
494
e.Name = telType;
495
e.LabelTemplate = "%PercentOfTotal";
496
e.YValue = Convert.ToDouble(row[yColumn].ToString());
497
s.Elements.Add(e);
498
}
499
SC.Add(s);
500
chart.TempDirectory = "temp";
501
chart.Use3D = false;
502
chart.DefaultAxis.Interval = 10;
503
chart.DefaultAxis.CultureName = "zh-CN";
504
chart.Palette = new Color[]
{ Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), Color.FromArgb(255, 99, 49), Color.FromArgb(0, 156, 255) };
505
chart.DefaultElement.SmartLabel.AutoWrap = true;
506
chart.Type = ChartType.ComboHorizontal;
507
chart.Size = width + "x" + height;
508
chart.DefaultElement.SmartLabel.Text = "";
509
chart.Title = title;
510
chart.DefaultElement.ShowValue = true;
511
chart.PieLabelMode = PieLabelMode.Outside;
512
chart.ShadingEffectMode = ShadingEffectMode.Three;
513
chart.NoDataLabel.Text = "没有数据显示";
514
chart.SeriesCollection.Add(SC);
515
}
516
}

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

241

242



243

244

245

246



247

248

249

250

251



252

253

254

255



256

257

258

259

260

261

262

263

264

265

266

267

268

269



270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286



287

288

289

290

291



292

293



294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311



312

313

314

315

316

317

318

319

320

321

322

323

324



325

326

327

328



329

330

331

332



333

334

335

336



337

338

339

340

341



342

343

344

345



346

347

348

349

350

351

352

353

354

355

356

357

358

359



360

361

362

363

364

365

366



367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383



384

385

386

387

388



389

390

391

392



393

394



395

396

397

398

399

400

401

402

403

404

405

406

407

408



409

410

411

412

413

414

415

416

417

418

419



420

421

422

423

424

425

426

427

428

429

430

431

432



433

434

435

436



437

438

439

440



441

442

443

444



445

446

447

448

449



450

451

452

453



454

455

456

457

458

459

460

461

462

463



464

465



466

467

468

469

470



471

472

473

474

475



476

477

478

479

480

481

482

483

484

485

486

487



488

489

490

491



492

493

494

495

496

497

498

499

500

501

502

503

504



505

506

507

508

509

510

511

512

513

514

515

516
