@@ -27,6 +27,7 @@ public partial class MainWindow : ContentPage
27
27
{
28
28
this .InitializeComponent ();
29
29
SfCircularChart chart = new SfCircularChart ();
30
+ this .Content = chart ;
30
31
}
31
32
}
32
33
```
@@ -70,37 +71,37 @@ namespace ChartGettingStarted
70
71
Now, let us define a simple data model that represents a data point in the chart.
71
72
###### C#
72
73
``` C#
73
- public class Sales
74
+ public class SalesModel
74
75
{
75
76
public string Product { get ; set ; }
76
77
public double SalesRate { get ; set ; }
77
78
}
78
79
```
79
80
80
- Next, create a view model class and initialize a list of ` Model ` objects as follows.
81
+ Next, create a SalesViewModel class and initialize a list of ` SalesModel ` objects as follows.
81
82
######
82
83
``` C#
83
- public class ChartViewModel
84
+ public class SalesViewModel
84
85
{
85
- public List <Sales > Data { get ; set ; }
86
+ public List <SalesModel > Data { get ; set ; }
86
87
87
- public ChartViewModel ()
88
+ public SalesViewModel ()
88
89
{
89
- Data = new List <Sales >()
90
+ Data = new List <SalesModel >()
90
91
{
91
- new Sales (){Product = " iPad" , SalesRate = 25 },
92
- new Sales (){Product = " iPhone" , SalesRate = 35 },
93
- new Sales (){Product = " MacBook" , SalesRate = 15 },
94
- new Sales (){Product = " Mac" , SalesRate = 5 },
95
- new Sales (){Product = " Others" , SalesRate = 10 },
92
+ new SalesModel (){Product = " iPad" , SalesRate = 25 },
93
+ new SalesModel (){Product = " iPhone" , SalesRate = 35 },
94
+ new SalesModel (){Product = " MacBook" , SalesRate = 15 },
95
+ new SalesModel (){Product = " Mac" , SalesRate = 5 },
96
+ new SalesModel (){Product = " Others" , SalesRate = 10 },
96
97
};
97
98
}
98
99
}
99
100
```
100
101
101
- * Create a ` ViewModel ` instance and set it as the chart's ` BindingContext ` . This enables property binding from ` ViewModel ` class.
102
+ * Create a ` SalesViewModel ` instance and set it as the chart's ` BindingContext ` . This enables property binding from ` SalesViewModel ` class.
102
103
103
- * Add namespace of ` ViewModel ` class to your XAML Page, if you prefer to set ` BindingContext ` in XAML.
104
+ * Add namespace of ` SalesViewModel ` class to your XAML Page, if you prefer to set ` BindingContext ` in XAML.
104
105
###### Xaml
105
106
``` xaml
106
107
<ContentPage
@@ -110,15 +111,16 @@ public class ChartViewModel
110
111
111
112
<chart : SfCircularChart >
112
113
<chart : SfCircularChart .BindingContext>
113
- <model : ChartViewModel />
114
+ <model : SalesViewModel />
114
115
</chart : SfCircularChart .BindingContext>
115
116
</chart : SfCircularChart >
116
117
</ContentPage >
117
118
```
118
119
###### C#
119
120
``` C#
120
- ChartViewModel viewModel = new ChartViewModel ();
121
- chart .BindingContext = viewModel ;
121
+ SfCircularChart chart = new SfCircularChart ();
122
+ this .BindingContext = new SalesViewModel ();
123
+ this .Content = chart ;
122
124
```
123
125
124
126
## Populate chart with data
@@ -141,7 +143,7 @@ Adding [PieSeries](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.Pi
141
143
###### C#
142
144
``` C#
143
145
SfCircularChart chart = new SfCircularChart ();
144
- ChartViewModel viewModel = new ChartViewModel ();
146
+ SalesViewModel viewModel = new SalesViewModel ();
145
147
chart .BindingContext = viewModel ;
146
148
PieSeries series = new PieSeries ();
147
149
series .ItemsSource = viewModel .Data ;
@@ -240,7 +242,7 @@ The following code example gives you the complete code of above configurations.
240
242
<Label Text =" PRODUCT SALES" />
241
243
</chart : SfCircularChart .Title>
242
244
<chart : SfCircularChart .BindingContext>
243
- <model : ChartViewModel />
245
+ <model : SalesViewModel />
244
246
</chart : SfCircularChart .BindingContext>
245
247
<chart : SfCircularChart .Legend>
246
248
<chart : ChartLegend />
@@ -267,7 +269,7 @@ public partial class MainPage : ContentPage
267
269
Text = " PRODUCT SALES"
268
270
};
269
271
chart .Legend = new ChartLegend ();
270
- ChartViewModel viewModel = new ChartViewModel ();
272
+ SalesViewModel viewModel = new SalesViewModel ();
271
273
chart .BindingContext = viewModel ;
272
274
273
275
PieSeries series = new PieSeries ();
0 commit comments