Skip to content

Commit c1c4b71

Browse files
Merge pull request #3 from SyncfusionExamples/917099-Update-GettingStarted_CartesianChart_MAUI-sample
917099-Updated Getting Started Cartesian Chart MAUI sample
2 parents 24dd16d + 1b2208c commit c1c4b71

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

Cartesian_chart_sample/CartesianChartSample/MainPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
<ContentPage.BindingContext>
11-
<model:ViewModel></model:ViewModel>
11+
<model:PersonViewModel/>
1212
</ContentPage.BindingContext>
1313

1414
<ContentPage.Content>

Cartesian_chart_sample/CartesianChartSample/ViewModel.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
namespace CartesianChartSample
88
{
9-
public class ViewModel
9+
public class PersonViewModel
1010
{
11-
public List<Person> Data { get; set; }
12-
public ViewModel()
11+
public List<PersonModel> Data { get; set; }
12+
public PersonViewModel()
1313
{
14-
Data = new List<Person>()
14+
Data = new List<PersonModel>()
1515
{
16-
new Person { Name = "David", Height = 170 },
17-
new Person { Name = "Michael", Height = 96 },
18-
new Person { Name = "Steve", Height = 65 },
19-
new Person { Name = "Joel", Height = 182 },
20-
new Person { Name = "Bob", Height = 134 }
16+
new PersonModel { Name = "David", Height = 170 },
17+
new PersonModel { Name = "Michael", Height = 96 },
18+
new PersonModel { Name = "Steve", Height = 65 },
19+
new PersonModel { Name = "Joel", Height = 182 },
20+
new PersonModel { Name = "Bob", Height = 134 }
2121
};
2222
}
2323

2424
}
25-
public class Person
25+
public class PersonModel
2626
{
2727
public string Name { get; set; }
2828
public double Height { get; set; }

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<ContentPage
1313
. . .
1414
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts">
15-
<Grid>
16-
<chart:SfCartesianChart/>
17-
</Grid>
15+
16+
<chart:SfCartesianChart/>
17+
1818
</ContentPage>
1919
```
2020
###### C#
@@ -28,6 +28,7 @@ namespace ChartGettingStarted
2828
{
2929
InitializeComponent();
3030
SfCartesianChart chart = new SfCartesianChart();
31+
this.Content = chart;
3132
}
3233
}
3334
}
@@ -71,36 +72,36 @@ namespace ChartGettingStarted
7172
Now, let us define a simple data model that represents a data point in the chart.
7273
######
7374
```C#
74-
public class Person
75+
public class PersonModel
7576
{
7677
public string Name { get; set; }
7778
public double Height { get; set; }
7879
}
7980
```
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.
8182
###### C#
8283
```C#
83-
public class ViewModel
84+
public class PersonViewModel
8485
{
85-
public List<Person> Data { get; set; }
86+
public List<PersonModel> Data { get; set; }
8687

87-
public ViewModel()
88+
public PersonViewModel()
8889
{
89-
Data = new List<Person>()
90+
Data = new List<PersonModel>()
9091
{
91-
new Person { Name = "David", Height = 170 },
92-
new Person { Name = "Michael", Height = 96 },
93-
new Person { Name = "Steve", Height = 65 },
94-
new Person { Name = "Joel", Height = 182 },
95-
new Person { Name = "Bob", Height = 134 }
92+
new PersonModel { Name = "David", Height = 170 },
93+
new PersonModel { Name = "Michael", Height = 96 },
94+
new PersonModel { Name = "Steve", Height = 65 },
95+
new PersonModel { Name = "Joel", Height = 182 },
96+
new PersonModel { Name = "Bob", Height = 134 }
9697
};
9798
}
9899
}
99100
```
100101

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

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.
104105
###### Xaml
105106
```xaml
106107
<ContentPage
@@ -111,7 +112,7 @@ Set the `ViewModel` instance as the `BindingContext` of your page to bind `ViewM
111112
xmlns:model="clr-namespace:ChartGettingStarted">
112113

113114
<ContentPage.BindingContext>
114-
<model:ViewModel></model:ViewModel>
115+
<model:PersonViewModel/>
115116
</ContentPage.BindingContext>
116117
</ContentPage>
117118
```
@@ -153,7 +154,7 @@ Run the project and check if you get following output to make sure you have conf
153154

154155
## Populate Chart with data
155156

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

158159
* 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.
159160
* 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)
@@ -200,7 +201,7 @@ chart.YAxes.Add(secondaryAxis);
200201
ColumnSeries series = new ColumnSeries();
201202
series.Label = "Height";
202203
series.ShowDataLabels = true;
203-
series.ItemsSource = (new ViewModel()).Data;
204+
series.ItemsSource = (new PersonViewModel()).Data;
204205
series.XBindingPath = "Name";
205206
series.YBindingPath = "Height";
206207

@@ -279,17 +280,17 @@ The legend provides information about the data point displayed in the chart. The
279280
<chart:SfCartesianChart>
280281
. . .
281282
<chart:ColumnSeries Label="Height"
282-
ItemsSource="{Binding Data}"
283-
XBindingPath="Name"
284-
YBindingPath="Height">
283+
ItemsSource="{Binding Data}"
284+
XBindingPath="Name"
285+
YBindingPath="Height">
285286
</chart:ColumnSeries>
286287
</chart:SfCartesianChart>
287288
```
288289

289290
###### C#
290291
```C#
291292
ColumnSeries series = new ColumnSeries ();
292-
series.ItemsSource = (new ViewModel()).Data;
293+
series.ItemsSource = (new PersonViewModel()).Data;
293294
series.XBindingPath = "Name";
294295
series.YBindingPath = "Height";
295296
series.Label = "Height";
@@ -314,7 +315,7 @@ Tooltips are used to show information about the segment, when a user hovers over
314315
###### C#
315316
```C#
316317
ColumnSeries series = new ColumnSeries();
317-
series.ItemsSource = (new ViewModel()).Data;
318+
series.ItemsSource = (new PersonViewModel()).Data;
318319
series.XBindingPath = "Name";
319320
series.YBindingPath = "Height";
320321
series.EnableTooltip = true;
@@ -332,7 +333,7 @@ The following code example gives you the complete code of above configurations.
332333
xmlns:model="clr-namespace:ChartGettingStarted">
333334

334335
<ContentPage.BindingContext>
335-
<model:ViewModel></model:ViewModel>
336+
<model:PersonViewModel/>
336337
</ContentPage.BindingContext>
337338

338339
<ContentPage.Content>
@@ -411,7 +412,7 @@ namespace ChartGettingStarted
411412
{
412413
Label = "Height",
413414
ShowDataLabels = true,
414-
ItemsSource = (new ViewModel()).Data,
415+
ItemsSource = (new PersonViewModel()).Data,
415416
XBindingPath = "Name",
416417
YBindingPath = "Height",
417418
DataLabelSettings = new CartesianDataLabelSettings

0 commit comments

Comments
 (0)