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
Now, let us define a simple data model that represents a data point in the chart.
72
73
######
73
74
```C#
74
-
publicclassPerson
75
+
publicclassPersonModel
75
76
{
76
77
publicstringName { get; set; }
77
78
publicdoubleHeight { get; set; }
78
79
}
79
80
```
80
-
Next, create a view model class and initialize a list of `Person` objects as follows.
81
+
Next, create a PersonViewModel class and initialize a list of `PersonModel` objects as follows.
81
82
###### C#
82
83
```C#
83
-
publicclassViewModel
84
+
publicclassPersonViewModel
84
85
{
85
-
publicList<Person> Data { get; set; }
86
+
publicList<PersonModel> Data { get; set; }
86
87
87
-
publicViewModel()
88
+
publicPersonViewModel()
88
89
{
89
-
Data=newList<Person>()
90
+
Data=newList<PersonModel>()
90
91
{
91
-
newPerson { Name="David", Height=170 },
92
-
newPerson { Name="Michael", Height=96 },
93
-
newPerson { Name="Steve", Height=65 },
94
-
newPerson { Name="Joel", Height=182 },
95
-
newPerson { Name="Bob", Height=134 }
92
+
newPersonModel { Name="David", Height=170 },
93
+
newPersonModel { Name="Michael", Height=96 },
94
+
newPersonModel { Name="Steve", Height=65 },
95
+
newPersonModel { Name="Joel", Height=182 },
96
+
newPersonModel { Name="Bob", Height=134 }
96
97
};
97
98
}
98
99
}
99
100
```
100
101
101
-
Set the `ViewModel` instance as the `BindingContext` of your page to bind `ViewModel` properties to the chart.
102
+
Set the `PersonViewModel` instance as the `BindingContext` of your page to bind `PersonViewModel` properties to the chart.
102
103
103
-
* Add namespace of `ViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.
104
+
* Add namespace of `PersonViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.
104
105
###### Xaml
105
106
```xaml
106
107
<ContentPage
@@ -111,7 +112,7 @@ Set the `ViewModel` instance as the `BindingContext` of your page to bind `ViewM
111
112
xmlns:model="clr-namespace:ChartGettingStarted">
112
113
113
114
<ContentPage.BindingContext>
114
-
<model:ViewModel></model:ViewModel>
115
+
<model:PersonViewModel/>
115
116
</ContentPage.BindingContext>
116
117
</ContentPage>
117
118
```
@@ -153,7 +154,7 @@ Run the project and check if you get following output to make sure you have conf
153
154
154
155
## Populate Chart with data
155
156
156
-
As we are going to visualize the comparison of heights in the data model, add [ColumnSeries](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ColumnSeries.html?tabs=tabid-1) to [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_Series) property of chart, and then bind the `Data` property of the above `ViewModel` to the `ColumnSeries.ItemsSource` as follows.
157
+
As we are going to visualize the comparison of heights in the data model, add [ColumnSeries](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ColumnSeries.html?tabs=tabid-1) to [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_Series) property of chart, and then bind the `Data` property of the above `PersonViewModel` to the `ColumnSeries.ItemsSource` as follows.
157
158
158
159
* The cartesian chart has [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_Series) as its default content.
159
160
* You need to set [XBindingPath](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_XBindingPath) and [YBindingPath](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.XYDataSeries.html#Syncfusion_Maui_Charts_XYDataSeries_YBindingPath)
0 commit comments