/
Form1.cs
77 lines (71 loc) · 3.2 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;
namespace WindowsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
Dictionary<string, string> productEncodeTable;
Dictionary<string, string> ProductEncodeTable {
get {
if(productEncodeTable == null)
productEncodeTable = new Dictionary<string, string>();
return productEncodeTable;
}
}
Dictionary<string, string> categoryEncodeTable;
Dictionary<string, string> CategoryEncodeTable {
get {
if(categoryEncodeTable == null)
categoryEncodeTable = new Dictionary<string, string>();
return categoryEncodeTable;
}
}
void CreateEncodeTables() {
int productCounter = 1;
foreach(object value in fieldProductName.GetUniqueValues()) {
ProductEncodeTable.Add(value.ToString(), "Products: " + productCounter++);
}
int categoryCounter = 1;
foreach(object value in fieldCategoryName.GetUniqueValues()) {
CategoryEncodeTable.Add(value.ToString(), "Category: " + categoryCounter++);
}
}
private void Form1_Load(object sender, EventArgs e) {
this.productReportsTableAdapter.Fill(this.nwindDataSet.ProductReports);
pivotGridControl1.OptionsChartDataSource.ProvideRowFieldValuesAsType = typeof(string);
pivotGridControl1.OptionsChartDataSource.ProvideColumnFieldValuesAsType = typeof(string);
pivotGridControl1.OptionsChartDataSource.ProvideCellValuesAsType = typeof(int);
CreateEncodeTables();
chartControl1.DataSource = pivotGridControl1;
fieldCategoryName.CollapseAll();
fieldCategoryName.ExpandValue("Produce");
}
#region #CustomChartDataSourceData
private void pivotGridControl1_CustomChartDataSourceData(object sender,
PivotCustomChartDataSourceDataEventArgs e) {
if(e.ItemType == PivotChartItemType.RowItem) {
if(e.FieldValueInfo.Field == fieldCategoryName) {
e.Value = CategoryEncodeTable[e.FieldValueInfo.Value.ToString()];
} else if(e.FieldValueInfo.Field == fieldProductName) {
string product =
ProductEncodeTable[e.FieldValueInfo.Value.ToString()];
string category =
CategoryEncodeTable[e.FieldValueInfo.GetHigherLevelFieldValue(fieldCategoryName).ToString()];
e.Value = product + '[' + category + ']';
}
}
if(e.ItemType == PivotChartItemType.ColumnItem) {
if(e.FieldValueInfo.ValueType == PivotGridValueType.GrandTotal) {
e.Value = "Total Sales";
}
}
if(e.ItemType == PivotChartItemType.CellItem) {
e.Value = Math.Round(Convert.ToDecimal(e.CellInfo.Value), 0);
}
}
#endregion #CustomChartDataSourceData
}
}