Skip to content

Commit 5a4caf4

Browse files
2 parents ee31b81 + 3666043 commit 5a4caf4

1 file changed

Lines changed: 61 additions & 131 deletions

File tree

README.md

Lines changed: 61 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@
77
3. To initialize the control, import the Chart namespace.
88
4. Initialize [SfCircularChart](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCircularChart.html).
99

10-
{% tabs %}
11-
12-
{% highlight xaml %}
13-
10+
###### Xaml
11+
```xaml
1412
<ContentPage
1513
. . .
1614
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts">
1715

1816
<chart:SfCircularChart/>
1917
</ContentPage>
20-
21-
{% endhighlight %}
22-
23-
{% highlight C# %}
18+
```
2419

20+
###### C#
21+
```C#
2522
using Syncfusion.Maui.Charts;
2623
. . .
27-
2824
public partial class MainWindow : ContentPage
2925
{
3026
public MainPage()
@@ -33,16 +29,14 @@ public partial class MainWindow : ContentPage
3329
SfCircularChart chart = new SfCircularChart();
3430
}
3531
}
36-
{% endhighlight %}
37-
38-
{% endtabs %}
32+
```
3933

4034
## Register the handler
4135

4236
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.
4337

44-
{% highlight C# %}
45-
38+
######
39+
```C#
4640
using Microsoft.Maui;
4741
using Microsoft.Maui.Hosting;
4842
using Microsoft.Maui.Controls.Compatibility;
@@ -69,33 +63,23 @@ namespace ChartGettingStarted
6963
}
7064
}
7165
}
72-
73-
{% endhighlight %}
66+
```
7467

7568
## Initialize view model
7669

7770
Now, let us define a simple data model that represents a data point in the chart.
78-
79-
{% tabs %}
80-
81-
{% highlight c# %}
82-
71+
###### C#
72+
```C#
8373
public class Sales
8474
{
8575
public string Product { get; set; }
8676
public double SalesRate { get; set; }
8777
}
88-
89-
{% endhighlight %}
90-
91-
{% endtabs %}
78+
```
9279

9380
Next, create a view model class and initialize a list of `Model` objects as follows.
94-
95-
{% tabs %}
96-
97-
{% highlight c# %}
98-
81+
######
82+
```C#
9983
public class ChartViewModel
10084
{
10185
public List<Sales> Data { get; set; }
@@ -112,19 +96,13 @@ public class ChartViewModel
11296
};
11397
}
11498
}
99+
```
115100

116-
{% endhighlight %}
117-
118-
{% endtabs %}
119-
120-
Create a `ViewModel` instance and set it as the chart's `BindingContext`. This enables property binding from `ViewModel` class.
121-
122-
N> Add namespace of `ViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.
123-
124-
{% tabs %}
125-
126-
{% highlight xaml %}
101+
* Create a `ViewModel` instance and set it as the chart's `BindingContext`. This enables property binding from `ViewModel` class.
127102

103+
* Add namespace of `ViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.
104+
###### Xaml
105+
```xaml
128106
<ContentPage
129107
. . .
130108
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
@@ -136,41 +114,32 @@ N> Add namespace of `ViewModel` class to your XAML Page, if you prefer to set `B
136114
</chart:SfCircularChart.BindingContext>
137115
</chart:SfCircularChart>
138116
</ContentPage>
139-
140-
{% endhighlight %}
141-
142-
{% highlight C# %}
143-
117+
```
118+
###### C#
119+
```C#
144120
ChartViewModel viewModel = new ChartViewModel();
145121
chart.BindingContext = viewModel;
146-
147-
{% endhighlight %}
148-
149-
{% endtabs %}
122+
```
150123

151124
## Populate chart with data
152125

153126
Adding [PieSeries](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.PieSeries.html) to the charts [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCircularChart.html#Syncfusion_Maui_Charts_SfCircularChart_Series) collection and binding `Data` to the series [ItemsSource](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_ItemsSource) property from its BindingContext to create our own Product Sales Pie chart.
154127

155-
N> The circular chart has [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCircularChart.html#Syncfusion_Maui_Charts_SfCircularChart_Series) as its default content.
156-
157-
N> To plot the series, the [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.CircularSeries.html#Syncfusion_Maui_Charts_CircularSeries_YBindingPath) properties must be configured so that the chart may get values from the respective properties in the data model.
128+
* The circular chart has [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCircularChart.html#Syncfusion_Maui_Charts_SfCircularChart_Series) as its default content.
158129

159-
{% tabs %}
160-
161-
{% highlight xaml %}
130+
* To plot the series, the [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.CircularSeries.html#Syncfusion_Maui_Charts_CircularSeries_YBindingPath) properties must be configured so that the chart may get values from the respective properties in the data model.
162131

132+
###### Xaml
133+
```xaml
163134
<chart:SfCircularChart>
164135
. . .
165136
<chart:PieSeries ItemsSource="{Binding Data}"
166137
XBindingPath="Product"
167138
YBindingPath="SalesRate"/>
168139
</chart:SfCircularChart>
169-
170-
{% endhighlight %}
171-
172-
{% highlight C# %}
173-
140+
```
141+
###### C#
142+
```C#
174143
SfCircularChart chart = new SfCircularChart();
175144
ChartViewModel viewModel = new ChartViewModel();
176145
chart.BindingContext = viewModel;
@@ -179,127 +148,93 @@ series.ItemsSource = viewModel.Data;
179148
series.XBindingPath = "Product";
180149
series.YBindingPath = "SalesRate";
181150
chart.Series.Add(series);
182-
183-
{% endhighlight %}
184-
185-
{% endtabs %}
151+
```
186152

187153
## Add a title
188154

189155
The title of the chart acts as the title to provide quick information to the user about the data being plotted in the chart. You can set title using the [Title](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartBase.html#Syncfusion_Maui_Charts_ChartBase_Title) property of circular chart as follows.
190156

191-
{% tabs %}
192-
193-
{% highlight xaml %}
194-
157+
###### Xaml
158+
```xaml
195159
<chart:SfCircularChart>
196160
<chart:SfCircularChart.Title>
197161
<Label Text="PRODUCT SALES"/>
198162
</chart:SfCircularChart.Title>
199163
. . .
200164
</chart:SfCircularChart>
201-
202-
{% endhighlight %}
203-
204-
{% highlight C# %}
205-
165+
```
166+
###### C#
167+
```C#
206168
SfCircularChart chart = new SfCircularChart();
207169
chart.Title = new Label
208170
{
209171
Text = "PRODUCT SALES"
210172
};
211-
212-
{% endhighlight %}
213-
214-
{% endtabs %}
173+
```
215174

216175
## Enable the data labels
217176

218177
The [ShowDataLabels](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_ShowDataLabels) property of series can be used to enable data labels to improve the readability of the circular chart. The label visibility is set to `False` by default.
219178

220-
{% tabs %}
221-
222-
{% highlight xaml %}
223-
179+
###### Xaml
180+
```xaml
224181
<chart:SfCircularChart>
225182
. . .
226183
<chart:PieSeries ShowDataLabels="True"/>
227184
</chart:SfCircularChart>
228-
229-
{% endhighlight %}
230-
231-
{% highlight C# %}
232-
185+
```
186+
###### C#
187+
```C#
233188
SfCircularChart chart = new SfCircularChart();
234189
. . .
235190
PieSeries series = new PieSeries();
236191
series.ShowDataLabels = true;
237192
chart.Series.Add(series);
238-
239-
{% endhighlight %}
240-
241-
{% endtabs %}
193+
```
242194

243195
## Enable a legend
244196

245197
The legend provides information about the data point displayed in the circular chart. The [Legend](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartBase.html#Syncfusion_Maui_Charts_ChartBase_Legend) property of the chart was used to enable it.
246198

247-
{% tabs %}
248-
249-
{% highlight xaml %}
250-
199+
###### Xaml
200+
```xaml
251201
<chart:SfCircularChart>
252202
. . .
253203
<chart:SfCircularChart.Legend>
254204
<chart:ChartLegend/>
255205
</chart:SfCircularChart.Legend>
256206
</chart:SfCircularChart>
257-
258-
{% endhighlight %}
259-
260-
{% highlight C# %}
261-
207+
```
208+
###### C#
209+
```C#
262210
SfCircularChart chart = new SfCircularChart();
263211
. . .
264212
chart.Legend = new ChartLegend();
265-
266-
{% endhighlight %}
267-
268-
{% endtabs %}
213+
```
269214

270215
## Enable Tooltip
271216

272217
Tooltips are used to show information about the segment, when mouse over on it. Enable tooltip by setting series [EnableTooltip](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_EnableTooltip) property as true.
273218

274-
{% tabs %}
275-
276-
{% highlight xaml %}
277-
219+
###### Xaml
220+
```xaml
278221
<chart:SfCircularChart>
279222
. . .
280223
<chart:PieSeries EnableTooltip="True"/>
281224
</chart:SfCircularChart>
282-
283-
{% endhighlight %}
284-
285-
{% highlight C# %}
286-
225+
```
226+
###### C#
227+
```C#
287228
SfCircularChart chart = new SfCircularChart();
288229
. . .
289230
PieSeries series = new PieSeries();
290231
series.EnableTooltip = true;
291232
chart.Series.Add(series);
292-
293-
{% endhighlight %}
294-
295-
{% endtabs %}
233+
```
296234

297235
The following code example gives you the complete code of above configurations.
298-
299-
{% tabs %}
300-
301-
{% highlight xaml %}
302-
236+
###### Xaml
237+
```xaml
303238
<chart:SfCircularChart>
304239
<chart:SfCircularChart.Title>
305240
<Label Text="PRODUCT SALES"/>
@@ -317,11 +252,9 @@ The following code example gives you the complete code of above configurations.
317252
EnableTooltip="True"
318253
YBindingPath="SalesRate"/>
319254
</chart:SfCircularChart>
320-
321-
{% endhighlight %}
322-
323-
{% highlight C# %}
324-
255+
```
256+
###### C#
257+
```C#
325258
using Syncfusion.Maui.Charts;
326259
. . .
327260
public partial class MainPage : ContentPage
@@ -347,9 +280,6 @@ public partial class MainPage : ContentPage
347280
this.Content = chart;
348281
}
349282
}
350-
351-
{% endhighlight %}
352-
353-
{% endtabs %}
283+
```
354284

355285
![Pie chart in .NET MAUI Chart](Getting_started-images/MAUI_pie_chart.png)

0 commit comments

Comments
 (0)