Skip to content

Commit ebd676e

Browse files
Update README.md
1 parent 6d8c7e3 commit ebd676e

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

README.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,45 @@
22

33
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.
44

5+
![.NET MAUI Pie Chart](https://user-images.githubusercontent.com/13678478/137482460-7e72b3ac-70de-4619-b314-7cd8b51d5d59.png)
6+
57
## Register the handler.
68
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.
79

810
## Initialize Chart
911
Import the SfCircularChart namespace as shown below.
1012

11-
[XAML]
13+
**[XAML]**
1214

15+
```
1316
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
17+
```
1418

15-
[C#]
19+
**[C#]**
1620

21+
```
1722
using Syncfusion.Maui.Charts;
23+
```
1824
Initialize an empty chart and set as content,
1925

20-
[XAML]
26+
**[XAML]**
2127

28+
```
2229
<chart:SfCircularChart>
2330
. . .
2431
</chart:SfCircularChart>
32+
```
33+
**[C#]**
2534

26-
[C#]
27-
35+
```
2836
SfCircularChart chart = new SfCircularChart();
2937
. . .
3038
this.Content = chart;
31-
39+
```
3240
## Initialize view model
3341

3442
Now, let define a simple data model that represents a data point for .NET MAUI Pie Chart.
35-
43+
```
3644
public class Model
3745
{
3846
public string Country{ get; set; }
@@ -45,9 +53,9 @@ public class Model
4553
Counts = count;
4654
}
4755
}
48-
56+
```
4957
Create a view model class and initialize a list of objects as shown below,
50-
58+
```
5159
public class ViewModel
5260
{
5361
public ObservableCollection<Model> Data { get; set; }
@@ -64,34 +72,38 @@ public class ViewModel
6472
};
6573
}
6674
}
75+
```
76+
Set the ViewModel instance as the BindingContext of chart; this is done to bind properties of ViewModel to SfCircularChart.
6777

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.
6979
70-
Add namespace of ViewModel class in your XAML page if you prefer to set BindingContext in XAML.
80+
**[XAML]**
7181

72-
[XAML]
73-
74-
xmlns:viewModel ="clr-namespace:MauiApp"
82+
```
83+
xmlns:viewModel ="clr-namespace:MauiApp"
7584
. . .
7685
<chart:SfCircularChart>
7786
<chart:SfCircularChart.BindingContext>
7887
<viewModel:ViewModel/>
7988
</chart:SfCircularChart.BindingContext>
8089
</chart:SfCircularChart>
90+
```
91+
**[C#]**
8192

82-
[C#]
83-
84-
SfCircularChart chart = new SfCircularChart();
93+
```
94+
SfCircularChart chart = new SfCircularChart();
8595
chart.BindingContext = new ViewModel();
86-
96+
```
97+
8798
## How to populate data in .NET MAUI Pie Charts
8899

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.
90101

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.
92103
93-
[XAML]
104+
**[XAML]**
94105

106+
```
95107
<chart:SfCircularChart>
96108
97109
<chart:SfCircularChart.BindingContext>
@@ -107,20 +119,22 @@ chart.BindingContext = new ViewModel();
107119
</chart:SfCircularChart.Series>
108120
109121
</chart:SfCircularChart>
122+
```
123+
**[C#]**
110124

111-
[C#]
112-
113-
SfCircularChart chart = new SfCircularChart ();
125+
```
126+
SfCircularChart chart = new SfCircularChart ();
114127
115-
chart.BindingContext = new ViewModel();
128+
chart.BindingContext = new ViewModel();
116129
. . .
117130
var binding = new Binding() { Path = "Data" };
118131
var series = new PieSeries()
119132
{
120-
XBindingPath = " Country",
121-
YBindingPath = "Counts",
133+
XBindingPath = " Country",
134+
YBindingPath = "Counts",
122135
ShowDataLabels = true
123136
};
124137
125138
series.SetBinding(ChartSeries.ItemsSourceProperty, binding);
126139
chart.Series.Add(series);
140+
```

0 commit comments

Comments
 (0)