1+ using Android . App ;
2+ using Android . OS ;
3+ using Android . Support . V7 . App ;
4+ using Android . Runtime ;
5+ using Android . Widget ;
6+ using Org . Json ;
7+ using Com . Syncfusion . Treemap ;
8+ using Android . Graphics ;
9+
10+ namespace TreeMapSample
11+ {
12+ [ Activity ( Label = "@string/app_name" , Theme = "@style/AppTheme" , MainLauncher = true ) ]
13+ public class MainActivity : AppCompatActivity
14+ {
15+ protected override void OnCreate ( Bundle savedInstanceState )
16+ {
17+ base . OnCreate ( savedInstanceState ) ;
18+
19+ SfTreeMap treeMap = new SfTreeMap ( this ) ;
20+ treeMap . ColorValuePath = "Growth" ;
21+ treeMap . WeightValuePath = "Population" ;
22+ treeMap . LayoutType = Com . Syncfusion . Treemap . Enums . LayoutType . Squarified ;
23+ treeMap . ShowTooltip = true ;
24+
25+ LeafItemSetting leafItemSetting = new LeafItemSetting ( ) ;
26+ leafItemSetting . ShowLabels = true ;
27+ leafItemSetting . Gap = 2 ;
28+ leafItemSetting . LabelPath = "Country" ;
29+ treeMap . LeafItemSettings = leafItemSetting ;
30+
31+ TreeMapFlatLevel flatLevel = new TreeMapFlatLevel ( ) ;
32+ flatLevel . HeaderHeight = 20 ;
33+ flatLevel . GroupPath = "Continent" ;
34+ flatLevel . GroupGap = 5 ;
35+ flatLevel . ShowHeader = true ;
36+ flatLevel . GroupStrokeColor = Color . Gray ;
37+ flatLevel . GroupStrokeWidth = 1 ;
38+ flatLevel . HeaderStyle = new Style ( ) { TextColor = Color . Black } ;
39+ treeMap . Levels . Add ( flatLevel ) ;
40+
41+ LegendSetting legendSettings = new LegendSetting ( ) ;
42+ legendSettings . ShowLegend = true ;
43+ legendSettings . LegendSize = new Size ( 700 , 45 ) ;
44+ legendSettings . LabelStyle = new Style ( ) { TextColor = Color . Black } ;
45+ treeMap . LegendSettings = legendSettings ;
46+
47+ RangeColorMapping rangeColorMapping = new RangeColorMapping ( ) ;
48+
49+ Range range1 = new Range ( ) ;
50+ range1 . From = 0 ;
51+ range1 . To = 1 ;
52+ range1 . Color = Color . ParseColor ( "#77D8D8" ) ;
53+ range1 . LegendLabel = "1 % Growth" ;
54+
55+ Range range2 = new Range ( ) ;
56+ range2 . From = 0 ;
57+ range2 . To = 2 ;
58+ range2 . Color = Color . ParseColor ( "#AED960" ) ;
59+ range2 . LegendLabel = "2 % Growth" ;
60+
61+ Range range3 = new Range ( ) ;
62+ range3 . From = 0 ;
63+ range3 . To = 3 ;
64+ range3 . Color = Color . ParseColor ( "#FFAF51" ) ;
65+ range3 . LegendLabel = "3 % Growth" ;
66+
67+ Range range4 = new Range ( ) ;
68+ range4 . From = 0 ;
69+ range4 . To = 4 ;
70+ range4 . Color = Color . ParseColor ( "#F3D240" ) ;
71+ range4 . LegendLabel = "4 % Growth" ;
72+
73+ rangeColorMapping . Ranges . Add ( range1 ) ;
74+ rangeColorMapping . Ranges . Add ( range2 ) ;
75+ rangeColorMapping . Ranges . Add ( range3 ) ;
76+ rangeColorMapping . Ranges . Add ( range4 ) ;
77+
78+ treeMap . LeafItemColorMapping = rangeColorMapping ;
79+ treeMap . DataSource = GetDataSource ( ) ;
80+
81+ SetContentView ( treeMap ) ;
82+ }
83+
84+ JSONArray GetDataSource ( )
85+ {
86+ JSONArray array = new JSONArray ( ) ;
87+ array . Put ( getJsonObject ( "Asia" , "Indonesia" , 3 , 237641326 ) ) ;
88+ array . Put ( getJsonObject ( "Asia" , "Russia" , 2 , 152518015 ) ) ;
89+ array . Put ( getJsonObject ( "North America" , "United States" , 4 , 315645000 ) ) ;
90+ array . Put ( getJsonObject ( "North America" , "Mexico" , 2 , 112336538 ) ) ;
91+ array . Put ( getJsonObject ( "North America" , "Canada" , 1 , 35056064 ) ) ;
92+ array . Put ( getJsonObject ( "South America" , "Colombia" , 1 , 47000000 ) ) ;
93+ array . Put ( getJsonObject ( "South America" , "Brazil" , 3 , 193946886 ) ) ;
94+ array . Put ( getJsonObject ( "Africa" , "Nigeria" , 2 , 170901000 ) ) ;
95+ array . Put ( getJsonObject ( "Africa" , "Egypt" , 1 , 83661000 ) ) ;
96+ array . Put ( getJsonObject ( "Europe" , "Germany" , 1 , 81993000 ) ) ;
97+ array . Put ( getJsonObject ( "Europe" , "France" , 1 , 65605000 ) ) ;
98+ array . Put ( getJsonObject ( "Europe" , "UK" , 1 , 63181775 ) ) ;
99+
100+ return array ;
101+ }
102+
103+ JSONObject getJsonObject ( string continent , string country , double growth , double population )
104+ {
105+ JSONObject obj = new JSONObject ( ) ;
106+
107+ obj . Put ( "Continent" , continent ) ;
108+ obj . Put ( "Country" , country ) ;
109+ obj . Put ( "Growth" , growth ) ;
110+ obj . Put ( "Population" , population ) ;
111+
112+ return obj ;
113+ }
114+
115+ }
116+ }
0 commit comments