This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
/
Form1.cs
67 lines (60 loc) · 2.57 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
using DevExpress.XtraTreeMap;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Linq;
namespace HierarchicalDataAdapterSample {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
CreateTreeMapDataAdapter();
CreateTreeMapColorizer();
}
#region #CreateDataAdapter
void CreateTreeMapDataAdapter() {
TreeMapHierarchicalDataAdapter dataAdapter = new TreeMapHierarchicalDataAdapter();
dataAdapter.DataSource = CreateStatistics();
// Fill the Mappings collection using mappings specifying
// how to convert data objects to tree map items.
dataAdapter.Mappings.Add(new TreeMapHierarchicalDataMapping {
Type = typeof(CountryStatistics),
LabelDataMember = "Name",
ChildrenDataMember = "EnergyStatistics"
});
dataAdapter.Mappings.Add(new TreeMapHierarchicalDataMapping {
Type = typeof(EnergyInfo),
LabelDataMember = "Type",
ValueDataMember = "Value"
});
treeMap.DataAdapter = dataAdapter;
}
#endregion #CreateDataAdapter
#region #GradientColorizer
void CreateTreeMapColorizer() {
treeMap.Colorizer = new TreeMapGradientColorizer {
StartColor = Color.Black,
EndColor = Color.White
};
}
#endregion #GradientColorizer
List<CountryStatistics> CreateStatistics() {
List<CountryStatistics> statistics = new List<CountryStatistics>();
XDocument doc = XDocument.Load("..\\..\\Data\\EnergyStatistic.xml");
foreach(XElement xCountry in doc.Element("ArrayOfEnergyStatistic").Elements("CountryEnergyInfo")) {
CountryStatistics countryStatistics = new CountryStatistics();
countryStatistics.Name = xCountry.Attribute("Country").Value;
foreach(XElement xEnergyInfo in xCountry.Elements("EnergyStatistic")) {
countryStatistics.EnergyStatistics.Add(new EnergyInfo {
Type = xEnergyInfo.Attribute("TypeName").Value,
Value = Convert.ToDouble(xEnergyInfo.Attribute("Value").Value)
});
}
statistics.Add(countryStatistics);
}
return statistics;
}
}
}