You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-27Lines changed: 41 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,37 +2,45 @@
2
2
3
3
A .NET MAUI Pie charts visual representation of percentages at a certain point in time and it can be used to show percentages of a whole. This section explains how to create a beautiful .NET MAUI Pie Charts.
4
4
5
+

6
+
5
7
## Register the handler.
6
8
Syncfusion.Maui.Core nuget is a dependent package for all Syncfusion controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion core. For more details refer this link.
7
9
8
10
## Initialize Chart
9
11
Import the SfCircularChart namespace as shown below.
Now, let define a simple data model that represents a data point for .NET MAUI Pie Chart.
35
-
43
+
```
36
44
public class Model
37
45
{
38
46
public string Country{ get; set; }
@@ -45,9 +53,9 @@ public class Model
45
53
Counts = count;
46
54
}
47
55
}
48
-
56
+
```
49
57
Create a view model class and initialize a list of objects as shown below,
50
-
58
+
```
51
59
public class ViewModel
52
60
{
53
61
public ObservableCollection<Model> Data { get; set; }
@@ -64,34 +72,38 @@ public class ViewModel
64
72
};
65
73
}
66
74
}
75
+
```
76
+
Set the ViewModel instance as the BindingContext of chart; this is done to bind properties of ViewModel to SfCircularChart.
67
77
68
-
Set the ViewModel instance as the BindingContext of chart; this is done to bind properties of ViewModel to SfCircularChart.
78
+
> Note: Add namespace of ViewModel class in your XAML page if you prefer to set BindingContext in XAML.
69
79
70
-
Add namespace of ViewModel class in your XAML page if you prefer to set BindingContext in XAML.
80
+
**[XAML]**
71
81
72
-
[XAML]
73
-
74
-
xmlns:viewModel ="clr-namespace:MauiApp"
82
+
```
83
+
xmlns:viewModel ="clr-namespace:MauiApp"
75
84
. . .
76
85
<chart:SfCircularChart>
77
86
<chart:SfCircularChart.BindingContext>
78
87
<viewModel:ViewModel/>
79
88
</chart:SfCircularChart.BindingContext>
80
89
</chart:SfCircularChart>
90
+
```
91
+
**[C#]**
81
92
82
-
[C#]
83
-
84
-
SfCircularChart chart = new SfCircularChart();
93
+
```
94
+
SfCircularChart chart = new SfCircularChart();
85
95
chart.BindingContext = new ViewModel();
86
-
96
+
```
97
+
87
98
## How to populate data in .NET MAUI Pie Charts
88
99
89
-
As we are going to visualize the comparison of annual population of various countries in the data model, add PieSeries to SfCircularChart.Series property, and then bind the Data property of the above ViewModel to the PieSeries.ItemsSource property as shown below.
100
+
As we are going to visualize the comparison of annual population of various countries in the data model, add PieSeries to SfCircularChart.Series property, and then bind the Data property of the above ViewModel to the PieSeries.ItemsSource property as shown below.
90
101
91
-
Need to set XBindingPath and YBindingPath properties, so that series would fetch values from the respective properties in the data model to plot the series.
102
+
> Note: Need to set XBindingPath and YBindingPath properties, so that series would fetch values from the respective properties in the data model to plot the series.
92
103
93
-
[XAML]
104
+
**[XAML]**
94
105
106
+
```
95
107
<chart:SfCircularChart>
96
108
…
97
109
<chart:SfCircularChart.BindingContext>
@@ -107,20 +119,22 @@ chart.BindingContext = new ViewModel();
0 commit comments