Skip to content

Commit c1264d0

Browse files
Updated view model
1 parent 5b388e6 commit c1264d0

File tree

4 files changed

+26
-61
lines changed

4 files changed

+26
-61
lines changed

Chart_GettingStarted/Chart_GettingStarted/ChartViewModel.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

Chart_GettingStarted/Chart_GettingStarted/MainPage.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
x:Class="Chart_GettingStarted.MainPage">
77

88

9-
<chart:SfPyramidChart ItemsSource="{Binding Data}"
10-
ShowDataLabels="True"
11-
EnableTooltip="True"
12-
XBindingPath="Name"
13-
YBindingPath="Value">
9+
<chart:SfPyramidChart ItemsSource="{Binding Data}"
10+
ShowDataLabels="True"
11+
EnableTooltip="True"
12+
XBindingPath="Name"
13+
YBindingPath="Value">
1414

1515
<chart:SfPyramidChart.Title>
1616
<Label Text="Pyramid Stages" HorizontalOptions="Fill" HorizontalTextAlignment="Center" VerticalOptions="Center"/>
1717
</chart:SfPyramidChart.Title>
1818

1919
<chart:SfPyramidChart.BindingContext>
20-
<model:ChartViewModel/>
20+
<model:StageViewModel/>
2121
</chart:SfPyramidChart.BindingContext>
2222

2323
<chart:SfPyramidChart.Legend>

Chart_GettingStarted/Chart_GettingStarted/Stage.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public partial class MainWindow : ContentPage
2828
{
2929
this.InitializeComponent();
3030
SfPyramidChart chart = new SfPyramidChart();
31+
this.Content = chart;
3132
}
3233
}
3334
```
@@ -72,38 +73,38 @@ Now, let us define a simple data model that represents a data point in the chart
7273

7374
**[C#]**
7475
```
75-
public class Stage
76+
public class StageModel
7677
{
7778
public string Name { get; set; }
7879
public double Value { get; set; }
7980
}
8081
```
8182

82-
Next, create a view model class and initialize a list of `Model` objects as follows.
83+
Next, create a StageViewModel class and initialize a list of `StageModel` objects as follows.
8384

8485
**[C#]**
8586
```
86-
public class ChartViewModel
87+
public class StageViewModel
8788
{
88-
public List<Stage> Data { get; set; }
89+
public List<StageModel> Data { get; set; }
8990
90-
public ChartViewModel()
91+
public StageViewModel()
9192
{
92-
Data = new List<Stage>()
93+
Data = new List<StageModel>()
9394
{
94-
new Stage(){Name = "Stage A", Value = 12},
95-
new Stage(){Name = "Stage B", Value = 21},
96-
new Stage(){Name = "Stage C", Value = 29},
97-
new Stage(){Name = "Stage D", Value = 37},
95+
new StageModel(){Name = "Stage A", Value = 12},
96+
new StageModel(){Name = "Stage B", Value = 21},
97+
new StageModel(){Name = "Stage C", Value = 29},
98+
new StageModel(){Name = "Stage D", Value = 37},
9899
};
99100
}
100101
}
101102
```
102103

103-
Create a `ViewModel` instance and set it as the chart's `BindingContext`. This enables property binding from `ViewModel` class.
104+
Create a `StageViewModel` instance and set it as the chart's `BindingContext`. This enables property binding from `StageViewModel` class.
104105

105106
> **_Note:_**
106-
Add the namespace of `ViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.
107+
Add the namespace of `StageViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.
107108

108109
**[XAML]**
109110
```
@@ -114,16 +115,18 @@ Add the namespace of `ViewModel` class to your XAML Page, if you prefer to set `
114115
115116
<chart:SfPyramidChart>
116117
<chart:SfPyramidChart.BindingContext>
117-
<model:ChartViewModel/>
118+
<model:StageViewModel/>
118119
</chart:SfPyramidChart.BindingContext>
119120
</chart:SfPyramidChart>
120121
</ContentPage>
121122
```
122123

123124
**[C#]**
124125
```
125-
ChartViewModel viewModel = new ChartViewModel();
126+
SfPyramidChart chart = new SfPyramidChart();
127+
StageViewModel viewModel = new StageViewModel();
126128
chart.BindingContext = viewModel;
129+
this.Content = chart;
127130
```
128131

129132
## Populate chart with data
@@ -142,7 +145,7 @@ chart.BindingContext = viewModel;
142145
**[C#]**
143146
```
144147
SfPyramidChart chart = new SfPyramidChart();
145-
ChartViewModel viewModel = new ChartViewModel();
148+
StageViewModel viewModel = new StageViewModel();
146149
chart.BindingContext = viewModel;
147150
chart.ItemsSource = viewModel.Data;
148151
chart.XBindingPath = "Name";
@@ -243,7 +246,7 @@ The following code example gives you the complete code of above configurations.
243246
<Label Text="Pyramid Stages"/>
244247
</chart:SfPyramidChart.Title>
245248
<chart:SfPyramidChart.BindingContext>
246-
<model:ChartViewModel/>
249+
<model:StageViewModel/>
247250
</chart:SfPyramidChart.BindingContext>
248251
<chart:SfPyramidChart.Legend>
249252
<chart:ChartLegend/>
@@ -265,7 +268,7 @@ public partial class MainPage : ContentPage
265268
Text = "Pyramid Stages"
266269
};
267270
chart.Legend = new ChartLegend();
268-
ChartViewModel viewModel = new ChartViewModel();
271+
StageViewModel viewModel = new StageViewModel();
269272
chart.BindingContext = viewModel;
270273
271274
chart.ItemsSource = viewModel.Data;

0 commit comments

Comments
 (0)