Skip to content

Commit 6d2f99b

Browse files
Merge pull request #1 from SyncfusionExamples/Bind-the-WinUI-circular-pie-chart-data-label-to-Others-category-values
WINUI-3442-Bind the WinUI circular pie chart data label to others category values.
2 parents d776e3d + 79febce commit 6d2f99b

23 files changed

+593
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
2+
<!-- Licensed under the MIT License. -->
3+
4+
<Application
5+
x:Class="PieChart_GroupedDataLabel.App"
6+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
7+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
8+
xmlns:local="using:PieChart_GroupedDataLabel">
9+
<Application.Resources>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
13+
<!-- Other merged dictionaries here -->
14+
</ResourceDictionary.MergedDictionaries>
15+
<!-- Other app resources here -->
16+
</ResourceDictionary>
17+
</Application.Resources>
18+
</Application>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation and Contributors.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using Microsoft.UI.Xaml.Controls.Primitives;
7+
using Microsoft.UI.Xaml.Data;
8+
using Microsoft.UI.Xaml.Input;
9+
using Microsoft.UI.Xaml.Media;
10+
using Microsoft.UI.Xaml.Navigation;
11+
using Microsoft.UI.Xaml.Shapes;
12+
using System;
13+
using System.Collections.Generic;
14+
using System.IO;
15+
using System.Linq;
16+
using System.Runtime.InteropServices.WindowsRuntime;
17+
using Windows.ApplicationModel;
18+
using Windows.ApplicationModel.Activation;
19+
using Windows.Foundation;
20+
using Windows.Foundation.Collections;
21+
22+
// To learn more about WinUI, the WinUI project structure,
23+
// and more about our project templates, see: http://aka.ms/winui-project-info.
24+
25+
namespace PieChart_GroupedDataLabel
26+
{
27+
/// <summary>
28+
/// Provides application-specific behavior to supplement the default Application class.
29+
/// </summary>
30+
public partial class App : Application
31+
{
32+
/// <summary>
33+
/// Initializes the singleton application object. This is the first line of authored code
34+
/// executed, and as such is the logical equivalent of main() or WinMain().
35+
/// </summary>
36+
public App()
37+
{
38+
this.InitializeComponent();
39+
}
40+
41+
/// <summary>
42+
/// Invoked when the application is launched.
43+
/// </summary>
44+
/// <param name="args">Details about the launch request and process.</param>
45+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
46+
{
47+
m_window = new MainWindow();
48+
m_window.Activate();
49+
}
50+
51+
private Window m_window;
52+
}
53+
}
432 Bytes
Loading
5.25 KB
Loading
1.71 KB
Loading
637 Bytes
Loading
283 Bytes
Loading
456 Bytes
Loading
2.05 KB
Loading
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
2+
<!-- Licensed under the MIT License. -->
3+
4+
<Window
5+
x:Class="PieChart_GroupedDataLabel.MainWindow"
6+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
7+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
8+
xmlns:local="using:PieChart_GroupedDataLabel"
9+
xmlns:chart="using:Syncfusion.UI.Xaml.Charts"
10+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
11+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
12+
mc:Ignorable="d">
13+
<Grid>
14+
<Grid.DataContext>
15+
<local:ViewModel x:Name="viewModel"/>
16+
</Grid.DataContext>
17+
<Grid.Resources>
18+
<local:DataLabelXValueConverter x:Key="dataLabelXValue"/>
19+
<local:DataLabelYValueConverter x:Key="dataLabelYValue" />
20+
<DataTemplate x:Key="dataMarkerTemplate">
21+
<StackPanel BorderBrush="Black" BorderThickness="1" CornerRadius="2" Orientation="Horizontal">
22+
<TextBlock Foreground="Black" FontWeight="Bold" Text="{Binding Converter={StaticResource dataLabelXValue}}" />
23+
<TextBlock Text=": " Foreground="Black" FontWeight="Bold"/>
24+
<TextBlock Foreground="Black" FontWeight="Bold" Text="{Binding Converter={StaticResource dataLabelYValue}}" />
25+
</StackPanel>
26+
</DataTemplate>
27+
<BrushCollection x:Key="customBrushes">
28+
<SolidColorBrush Color="#585DAC"/>
29+
<SolidColorBrush Color="#B28DD4"/>
30+
<SolidColorBrush Color="#5DAC88"/>
31+
<SolidColorBrush Color="#F2BB30"/>
32+
<SolidColorBrush Color="#E66C69"/>
33+
<SolidColorBrush Color="#27B9B4"/>
34+
<SolidColorBrush Color="#FB6690"/>
35+
</BrushCollection>
36+
</Grid.Resources>
37+
<Grid.ColumnDefinitions>
38+
<ColumnDefinition/>
39+
</Grid.ColumnDefinitions>
40+
<chart:SfCircularChart Margin="10">
41+
<chart:SfCircularChart.Header>
42+
<TextBlock Text="Sales Percentage" FontWeight="Bold" />
43+
</chart:SfCircularChart.Header>
44+
<chart:PieSeries XBindingPath="Product" ShowDataLabels="True" Radius="0.7"
45+
GroupTo="10" GroupMode="Percentage" YBindingPath="SalesPercentage"
46+
ItemsSource="{Binding Data}"
47+
PaletteBrushes="{StaticResource customBrushes}">
48+
<chart:PieSeries.DataLabelSettings>
49+
<chart:CircularDataLabelSettings ShowConnectorLine="True"
50+
Context="DataLabelItem"
51+
Position="OutsideExtended"
52+
UseSeriesPalette="True"
53+
ContentTemplate="{StaticResource dataMarkerTemplate}" />
54+
</chart:PieSeries.DataLabelSettings>
55+
56+
</chart:PieSeries>
57+
</chart:SfCircularChart>
58+
</Grid>
59+
</Window>

0 commit comments

Comments
 (0)