Skip to content

Commit 14c6ce6

Browse files
author
MoneeshramDhanabal
committed
Added Sample
1 parent a10074f commit 14c6ce6

File tree

9 files changed

+240
-0
lines changed

9 files changed

+240
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33103.201
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Custom_BarChart", "Custom_BarChart\Custom_BarChart.csproj", "{87B82981-0014-431C-A408-06FF4414A59F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{87B82981-0014-431C-A408-06FF4414A59F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{87B82981-0014-431C-A408-06FF4414A59F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{87B82981-0014-431C-A408-06FF4414A59F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{87B82981-0014-431C-A408-06FF4414A59F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {D478ED6F-2D05-4CF3-AFB6-F029CBE896C3}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="Custom_BarChart.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Custom_BarChart"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace Custom_BarChart
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net6.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<UseWPF>true</UseWPF>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.SfChart.WPF" Version="20.3.0.61" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
<ItemGroup>
5+
<ApplicationDefinition Update="App.xaml">
6+
<SubType>Designer</SubType>
7+
</ApplicationDefinition>
8+
</ItemGroup>
9+
<ItemGroup>
10+
<Page Update="MainWindow.xaml">
11+
<SubType>Designer</SubType>
12+
</Page>
13+
</ItemGroup>
14+
</Project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<Window x:Class="Custom_BarChart.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
7+
xmlns:local="clr-namespace:Custom_BarChart"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
11+
<Grid>
12+
<Grid.DataContext>
13+
<local:ViewModel/>
14+
</Grid.DataContext>
15+
16+
<Grid.Resources>
17+
<local:InteriorConverter x:Key="interiorConverter"/>
18+
</Grid.Resources>
19+
20+
<chart:SfChart Margin="10">
21+
22+
<chart:SfChart.PrimaryAxis>
23+
<chart:CategoryAxis LabelFormat="yyyy"></chart:CategoryAxis>
24+
</chart:SfChart.PrimaryAxis>
25+
26+
<chart:SfChart.SecondaryAxis>
27+
<chart:NumericalAxis></chart:NumericalAxis>
28+
</chart:SfChart.SecondaryAxis>
29+
30+
<chart:ColumnSeries XBindingPath="Year" YBindingPath="India" ItemsSource="{Binding DataPoints}">
31+
<chart:ColumnSeries.CustomTemplate>
32+
<DataTemplate>
33+
<Canvas>
34+
<Rectangle Fill="{Binding Converter={StaticResource interiorConverter}}" Height="{Binding Height}" Width="{Binding Width}" Canvas.Left="{Binding RectX}" Canvas.Top="{Binding RectY}"></Rectangle>
35+
</Canvas>
36+
</DataTemplate>
37+
</chart:ColumnSeries.CustomTemplate>
38+
<chart:ColumnSeries.AdornmentsInfo>
39+
<chart:ChartAdornmentInfo AdornmentsPosition="TopAndBottom" LabelPosition="Center" SegmentLabelContent="LabelContentPath" ShowLabel="True" >
40+
<chart:ChartAdornmentInfo.LabelTemplate>
41+
<DataTemplate>
42+
<StackPanel Orientation="Horizontal">
43+
<Label Content="{Binding Item.India}" Foreground="White" FontSize="11"></Label>
44+
</StackPanel>
45+
</DataTemplate>
46+
</chart:ChartAdornmentInfo.LabelTemplate>
47+
</chart:ChartAdornmentInfo>
48+
</chart:ColumnSeries.AdornmentsInfo>
49+
</chart:ColumnSeries>
50+
51+
</chart:SfChart>
52+
</Grid>
53+
54+
</Window>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
using System.Windows.Media;
6+
using Syncfusion.UI.Xaml.Charts;
7+
8+
namespace Custom_BarChart
9+
{
10+
/// <summary>
11+
/// Interaction logic for MainWindow.xaml
12+
/// </summary>
13+
public partial class MainWindow : Window
14+
{
15+
public MainWindow()
16+
{
17+
InitializeComponent();
18+
}
19+
}
20+
21+
public class InteriorConverter : IValueConverter
22+
{
23+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
24+
{
25+
var ydata = (value as ColumnSegment).YData;
26+
Brush interior;
27+
28+
interior = ydata > 0 ?
29+
new SolidColorBrush(Colors.Green) :
30+
new SolidColorBrush(Colors.Red);
31+
32+
return interior;
33+
}
34+
35+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
36+
{
37+
throw new NotImplementedException();
38+
}
39+
}
40+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
4+
namespace Custom_BarChart
5+
{
6+
public class ViewModel
7+
{
8+
public ViewModel()
9+
{
10+
this.DataPoints = new ObservableCollection<Model>();
11+
DateTime year = new DateTime(2005, 5, 1);
12+
13+
DataPoints.Add(new Model() { Year = year.AddYears(1), India = 28, Germany = 31, England = 36, France = 39 });
14+
DataPoints.Add(new Model() { Year = year.AddYears(2), India = 25, Germany = 28, England = 32, France = 36 });
15+
DataPoints.Add(new Model() { Year = year.AddYears(3), India = 26, Germany = 30, England = 34, France = 40 });
16+
DataPoints.Add(new Model() { Year = year.AddYears(4), India = -27, Germany = 36, England = 41, France = 44 });
17+
DataPoints.Add(new Model() { Year = year.AddYears(5), India = -32, Germany = 36, England = 42, France = 45 });
18+
DataPoints.Add(new Model() { Year = year.AddYears(6), India = 35, Germany = 39, England = 42, France = 48 });
19+
DataPoints.Add(new Model() { Year = year.AddYears(7), India = -30, Germany = 38, England = 43, France = 46 });
20+
}
21+
22+
public ObservableCollection<Model> DataPoints
23+
{
24+
get;
25+
set;
26+
}
27+
}
28+
29+
public class Model
30+
{
31+
public DateTime Year
32+
{
33+
get;
34+
set;
35+
}
36+
public double India
37+
{
38+
get;
39+
set;
40+
}
41+
public double Germany
42+
{
43+
get;
44+
set;
45+
}
46+
public double England
47+
{
48+
get;
49+
set;
50+
}
51+
public double France
52+
{
53+
get;
54+
set;
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)