Skip to content

Commit bd355ca

Browse files
committed
update the palette colors for doughnut chart
1 parent 834291c commit bd355ca

File tree

4 files changed

+64
-38
lines changed

4 files changed

+64
-38
lines changed

TreeMapChart/TreeMapChart/MainPage.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ private void UpdateDataBasedOnSelection(string country)
7171
"Australia" =>
7272
[
7373
new() { Category = "ODI World Cups", Titles = 6 },
74-
new() { Category = "T20 World Cups", Titles = 1 },
7574
new() { Category = "Champions Trophies", Titles = 2 },
75+
new() { Category = "T20 World Cups", Titles = 1 },
7676
new() { Category = "WTC", Titles = 1 }
7777
],
7878
"India" =>
7979
[
80+
new() { Category = "Champions Trophies", Titles = 3 },
8081
new() { Category = "ODI World Cups", Titles = 2 },
8182
new() { Category = "T20 World Cups", Titles = 2 },
82-
new() { Category = "Champions Trophies", Titles = 3 },
8383
],
8484
"England" =>
8585
[
86-
new() { Category = "ODI World Cups", Titles = 1 },
8786
new() { Category = "T20 World Cups", Titles = 2 },
87+
new() { Category = "ODI World Cups", Titles = 1 },
8888
],
8989
"West Indies" =>
9090
[

TreeMapChart/TreeMapChart/TitleBreakDownPage.Xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
Radius="0.8"
3535
ShowDataLabels="True"
3636
ItemsSource="{Binding SelectedCountryDetails}"
37-
PaletteBrushes="{Binding CustomBrushes}"
3837
XBindingPath="Category"
3938
YBindingPath="Titles">
4039
<chart:DoughnutSeries.CenterView>

TreeMapChart/TreeMapChart/TitleBreakDownPage.xaml.cs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,71 @@ public TitleBreakDownPage(ViewModel viewModel)
88
{
99
InitializeComponent();
1010
this.BindingContext = viewModel;
11-
pathData.Data = (Geometry?)(new PathGeometryConverter().ConvertFromInvariantString("M10.42167,25.733974L21.693511,25.733974 23.089492,31.219968 9.0256896,31.219968z M25.682455,4.4889958L25.682455,4.5879955C25.483458,6.9819931 25.084463,9.9749901 24.086477,12.966987 24.386473,12.966987 28.675413,13.365987 30.171391,5.7849941 30.071393,5.8849942 30.27139,4.4889957 28.87441,4.4889958L28.774411,4.4889958z M3.1407728,4.4889958C1.7437916,4.4889957 1.9437895,5.8849942 1.9437895,5.8849943 3.3397694,12.766987 7.0307174,13.066987 7.8287063,13.066987 7.1307163,10.871989 6.5317245,8.1789919 6.3327274,4.7879953L6.3327274,4.4889958 3.3397694,4.4889958z M6.232729,0L25.682455,0C25.682455,0,25.782454,0.89799929,25.782454,2.4939973L25.782454,2.6929972 28.974408,2.6929972C28.974408,2.6929975 32.365361,2.9919972 31.966367,5.8849943 31.966367,5.8849942 30.806497,15.067173 23.729957,14.973529L23.400065,14.962376 23.515435,14.692866C23.574677,14.550345,23.63236,14.407361,23.688483,14.263986L23.787481,13.864986 23.388487,14.961985 23.400065,14.962376 23.333035,15.118966C22.460016,17.100264,21.281517,18.976481,19.797538,20.547979L18.401557,20.547979 18.401557,24.137975 13.813622,24.137975 13.813622,20.547979 12.51664,20.547979C12.51664,20.547979,10.521668,19.050981,8.8256922,15.160985L8.7266936,14.961985 8.4266977,14.961985C1.2457991,15.160985 0.048815727,5.8849942 0.048815727,5.8849943 -0.45017719,2.8929973 3.0407734,2.6929975 3.0407734,2.6929972L6.232729,2.6929972 6.232729,2.1939979z"));
12-
label.Text = "Total Titles : " + viewModel.SelectedCountryTotalTitles.ToString();
1311

12+
if (viewModel.SelectedCountry != null)
13+
{
14+
series.PaletteBrushes = UpdateDataBasedOnSelection(viewModel.SelectedCountry);
15+
pathData.Data = (Geometry?)(new PathGeometryConverter().ConvertFromInvariantString("M10.42167,25.733974L21.693511,25.733974 23.089492,31.219968 9.0256896,31.219968z M25.682455,4.4889958L25.682455,4.5879955C25.483458,6.9819931 25.084463,9.9749901 24.086477,12.966987 24.386473,12.966987 28.675413,13.365987 30.171391,5.7849941 30.071393,5.8849942 30.27139,4.4889957 28.87441,4.4889958L28.774411,4.4889958z M3.1407728,4.4889958C1.7437916,4.4889957 1.9437895,5.8849942 1.9437895,5.8849943 3.3397694,12.766987 7.0307174,13.066987 7.8287063,13.066987 7.1307163,10.871989 6.5317245,8.1789919 6.3327274,4.7879953L6.3327274,4.4889958 3.3397694,4.4889958z M6.232729,0L25.682455,0C25.682455,0,25.782454,0.89799929,25.782454,2.4939973L25.782454,2.6929972 28.974408,2.6929972C28.974408,2.6929975 32.365361,2.9919972 31.966367,5.8849943 31.966367,5.8849942 30.806497,15.067173 23.729957,14.973529L23.400065,14.962376 23.515435,14.692866C23.574677,14.550345,23.63236,14.407361,23.688483,14.263986L23.787481,13.864986 23.388487,14.961985 23.400065,14.962376 23.333035,15.118966C22.460016,17.100264,21.281517,18.976481,19.797538,20.547979L18.401557,20.547979 18.401557,24.137975 13.813622,24.137975 13.813622,20.547979 12.51664,20.547979C12.51664,20.547979,10.521668,19.050981,8.8256922,15.160985L8.7266936,14.961985 8.4266977,14.961985C1.2457991,15.160985 0.048815727,5.8849942 0.048815727,5.8849943 -0.45017719,2.8929973 3.0407734,2.6929975 3.0407734,2.6929972L6.232729,2.6929972 6.232729,2.1939979z"));
16+
label.Text = "Total Titles : " + viewModel.SelectedCountryTotalTitles.ToString();
17+
}
1418
}
1519

1620
private void Button_Clicked(object sender, EventArgs e)
1721
{
1822
Navigation.PopAsync();
1923
}
24+
25+
private List<Brush> UpdateDataBasedOnSelection(string country)
26+
{
27+
return country switch
28+
{
29+
"Australia" =>
30+
[
31+
new SolidColorBrush(Color.FromArgb("#ffb300")),
32+
new SolidColorBrush(Color.FromArgb("#ffc933")),
33+
new SolidColorBrush(Color.FromArgb("#ffd966")),
34+
new SolidColorBrush(Color.FromArgb("#ffe699")),
35+
],
36+
"India" =>
37+
[
38+
new SolidColorBrush(Color.FromArgb("#1f8fff")),
39+
new SolidColorBrush(Color.FromArgb("#4da6ff")),
40+
new SolidColorBrush(Color.FromArgb("#80bdff")),
41+
],
42+
"England" =>
43+
[
44+
new SolidColorBrush(Color.FromArgb("#41b0f1")),
45+
new SolidColorBrush(Color.FromArgb("#6ec0f7")),
46+
],
47+
"West Indies" =>
48+
[
49+
new SolidColorBrush(Color.FromArgb("#800000")),
50+
new SolidColorBrush(Color.FromArgb("#b13939")),
51+
new SolidColorBrush(Color.FromArgb("#cc6666")),
52+
],
53+
"Pakistan" =>
54+
[
55+
new SolidColorBrush(Color.FromArgb("#004d00")),
56+
new SolidColorBrush(Color.FromArgb("#339933")),
57+
new SolidColorBrush(Color.FromArgb("#66cc66")),
58+
],
59+
"Sri Lanka" =>
60+
[
61+
new SolidColorBrush(Color.FromArgb("#00329e")),
62+
new SolidColorBrush(Color.FromArgb("#0056d6")),
63+
new SolidColorBrush(Color.FromArgb("#3388ff")),
64+
],
65+
"New Zealand" =>
66+
[
67+
new SolidColorBrush(Color.FromArgb("#305050")),
68+
new SolidColorBrush(Color.FromArgb("#6a8a8a")),
69+
],
70+
"South Africa" =>
71+
[
72+
new SolidColorBrush(Color.FromArgb("#228c22")),
73+
new SolidColorBrush(Color.FromArgb("#69bf69")),
74+
],
75+
_ => throw new NotImplementedException()
76+
};
77+
}
2078
}

TreeMapChart/TreeMapChart/ViewModel/ViewModel.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
22
using System.ComponentModel;
33

44
namespace TreeMapChart
@@ -72,28 +72,12 @@ public ObservableCollection<WorldCupStats>? SelectedCountryDetails
7272
}
7373
}
7474

75-
private ObservableCollection<Brush>? _customBrushes;
76-
77-
public ObservableCollection<Brush>? CustomBrushes
78-
{
79-
get => _customBrushes;
80-
set
81-
{
82-
if (_customBrushes != value)
83-
{
84-
_customBrushes = value;
85-
OnPropertyChanged(nameof(CustomBrushes));
86-
}
87-
}
88-
}
89-
9075
/// <summary>
9176
/// Initializes a new instance of the ViewModel class and loads initial data.
9277
/// </summary>
9378
public ViewModel()
9479
{
9580
CountryTitles = LoadCountryTitles();
96-
CustomBrushes = LoadCustomBrushes();
9781
}
9882

9983
/// <summary>
@@ -115,21 +99,6 @@ private static ObservableCollection<WorldCupStats> LoadCountryTitles()
11599
];
116100
}
117101

118-
/// <summary>
119-
/// Static method to get the initial collection of custom brushes.
120-
/// </summary>
121-
private static ObservableCollection<Brush> LoadCustomBrushes()
122-
{
123-
// Initialize collection with predefined cricket statistics
124-
return
125-
[
126-
new SolidColorBrush (Color.FromArgb("#1060DC")),
127-
new SolidColorBrush (Color.FromArgb("#00B553")),
128-
new SolidColorBrush (Color.FromArgb("#DA6902")),
129-
new SolidColorBrush (Color.FromArgb("#C71969")),
130-
];
131-
}
132-
133102
#region INotifyPropertyChanged Implementation
134103

135104
/// <summary>

0 commit comments

Comments
 (0)