Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WPF_Sample/Sample/App.xaml → CustomLegendSample/App.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Application x:Class="Sample.App"
<Application x:Class="CustomLegendSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustomLegendSample"
StartupUri="MainWindow.xaml">
<Application.Resources>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Sample
namespace CustomLegendSample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions CustomLegendSample/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
15 changes: 15 additions & 0 deletions CustomLegendSample/CustomLegendSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.SfChart.WPF" Version="*" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions CustomLegendSample/CustomLegendSample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomLegendSample", "CustomLegendSample.csproj", "{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
<Window x:Class="Sample1.MainWindow"
<Window x:Class="CustomLegendSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Sample1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
Title="Sample" WindowState="Maximized"
x:Name="window"
Height="500" Width="725">
xmlns:local="clr-namespace:CustomLegendSample"
mc:Ignorable="d"
Title="Sample" WindowState="Maximized" x:Name="window" Height="500" Width="725">

<Grid x:Name="grid" Margin="10">
<Grid.DataContext>
<local:ViewModel x:Name="viewModel"></local:ViewModel>
<local:ViewModel x:Name="viewModel"/>
</Grid.DataContext>

<Grid.Resources>
<DataTemplate x:Key="itemTemplate">

<StackPanel Margin="10,0,10,0" Orientation="Horizontal">

<CheckBox Margin="2" Tag="{Binding}"
IsChecked="True"
Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/>
IsChecked="True"
Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/>
<Rectangle Width="{Binding IconWidth}" Height="{Binding IconHeight}"
Fill="{Binding Interior}" Margin="2"/>

Fill="{Binding Interior}" Margin="2"/>

<TextBlock HorizontalAlignment="Center"
Margin="5,0,0,0"
VerticalAlignment="Center"
Text="{Binding Item.XValue}">
Margin="5,0,0,0"
VerticalAlignment="Center"
Text="{Binding Item.XValue}">

</TextBlock>

</StackPanel>

</DataTemplate>
</Grid.Resources>
<chart:SfChart x:Name="chart">

<chart:SfChart x:Name="chart">
<local:PieSeriesExt x:Name="series1" Label="Series" XBindingPath="XValue" YBindingPath="YValue" />
<local:PieSeriesExt x:Name="series2" XBindingPath="XValue" YBindingPath="YValue" />

</chart:SfChart>

</Grid>
</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
using Syncfusion.UI.Xaml.Charts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
using System.Reflection;

namespace Sample1
namespace CustomLegendSample
{
using Syncfusion.UI.Xaml.Charts;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
Expand Down Expand Up @@ -57,7 +39,7 @@ public MainWindow()

legend.ItemTemplate = grid.Resources["itemTemplate"] as DataTemplate;
chart.Legend = legend;

}

private void CheckBox_Checked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -103,44 +85,8 @@ private void UpdateArea()
info?.Invoke(chart, new object[] { true });
}
}
public class Model
{
public string XValue { get; set; }
public double YValue { get; set; }
}

public class ViewModel
{
public ViewModel()
{
GenerateData();
}

public void GenerateData()
{
Data = new ObservableCollection<Model>();
Random rd = new Random();
for (int i = 0; i < 6; i++)
{
Data.Add(new Model()
{
XValue = "Label" +i.ToString(),
YValue = rd.Next(0, 50)
});
}
}

private ObservableCollection<Model> data;

public ObservableCollection<Model> Data
{
get { return data; }
set { data = value; }
}

}

public class PieSeriesExt :PieSeries
public class PieSeriesExt : PieSeries
{
public ObservableCollection<ChartSegment> ChartSegments
{
Expand All @@ -150,5 +96,4 @@ public ObservableCollection<ChartSegment> ChartSegments
}
}
}

}
}
8 changes: 8 additions & 0 deletions CustomLegendSample/Model/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace CustomLegendSample
{
public class Model
{
public string XValue { get; set; }
public double YValue { get; set; }
}
}
35 changes: 35 additions & 0 deletions CustomLegendSample/ViewModel/ViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace CustomLegendSample
{
using System.Collections.ObjectModel;

public class ViewModel
{
public ViewModel()
{
GenerateData();
}

public void GenerateData()
{
Data = new ObservableCollection<Model>();
Random rd = new Random();
for (int i = 0; i < 6; i++)
{
Data.Add(new Model()
{
XValue = "Label" + i.ToString(),
YValue = rd.Next(0, 50)
});
}
}

private ObservableCollection<Model> data;

public ObservableCollection<Model> Data
{
get { return data; }
set { data = value; }
}

}
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ private void UpdateArea()

## Output:

The following demo image illustrates creating custom legend items, with and without toogle functionality in WPF, following the implemented steps.

![custom legend without toggle wpf chart.png](custom-legend-without-toggle.png)

![custom legend with toggle wpf chart](custom-legend-with-toggle.png)

KB article - [How to create custom legend items in WPF Chart?](https://www.syncfusion.com/kb/10675/how-to-create-custom-legend-items-in-wpf-chart)
## Troubleshooting

#### Path too long exception

If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to a shorter name before building the project.

For more details, refer to the KB on [How to create custom legend items in WPF Chart](https://www.syncfusion.com/kb/10675/how-to-create-custom-legend-items-in-wpf-chart).
28 changes: 0 additions & 28 deletions WPF_Sample/Sample.sln

This file was deleted.

6 changes: 0 additions & 6 deletions WPF_Sample/Sample/App.config

This file was deleted.

55 changes: 0 additions & 55 deletions WPF_Sample/Sample/Properties/AssemblyInfo.cs

This file was deleted.

Loading