Skip to content

Commit af9ae68

Browse files
Merge pull request #1 from SyncfusionExamples/910017-Update-blog-sample
910017 Update blog sample and readme
2 parents 38d9cd2 + 6473228 commit af9ae68

File tree

11 files changed

+595
-2
lines changed

11 files changed

+595
-2
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.11.35208.52
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ForecastFastLineChart", "ForecastFastLineChart\ForecastFastLineChart.csproj", "{11D9782B-EEDE-4B63-B284-7CD60D8CEB5B}"
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+
{11D9782B-EEDE-4B63-B284-7CD60D8CEB5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{11D9782B-EEDE-4B63-B284-7CD60D8CEB5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{11D9782B-EEDE-4B63-B284-7CD60D8CEB5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{11D9782B-EEDE-4B63-B284-7CD60D8CEB5B}.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 = {22EA7BAE-8676-4A56-86D5-0E40ACC6A80F}
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="ForecastFastLineChart.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:ForecastFastLineChart"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace ForecastFastLineChart
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<None Remove="data.csv" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<EmbeddedResource Include="data.csv" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Syncfusion.SfChart.WPF" Version="*" />
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<Window x:Class="ForecastFastLineChart.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:local="clr-namespace:ForecastFastLineChart"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800"
9+
xmlns:sync="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF">
10+
11+
<Border Padding="15,15,25,15" Margin="10" BorderBrush="Black" BorderThickness="2" CornerRadius="10">
12+
13+
<sync:SfChart x:Name="chart" HorizontalHeaderAlignment="Left">
14+
15+
<sync:SfChart.DataContext>
16+
<local:ViewModel x:Name="viewModel"/>
17+
</sync:SfChart.DataContext>
18+
19+
<sync:SfChart.Resources>
20+
<local:TooltipValueConverter x:Key="converter"/>
21+
<DataTemplate x:Key="labelTemplate">
22+
23+
<Border CornerRadius="5" BorderThickness="1"
24+
BorderBrush="Black" Background="White" Padding="10" Margin="8">
25+
26+
<StackPanel Orientation="Vertical">
27+
<TextBlock Foreground="Black" Background="LightGray" FontSize="15"
28+
Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=0}"/>
29+
<Grid Margin="0, 5, 0, 0">
30+
<Grid.RowDefinitions>
31+
<RowDefinition Height="20"/>
32+
<RowDefinition Height="20"/>
33+
<RowDefinition Height="20"/>
34+
<RowDefinition Height="20"/>
35+
<RowDefinition Height="20"/>
36+
<RowDefinition Height="20"/>
37+
</Grid.RowDefinitions>
38+
<Grid.ColumnDefinitions>
39+
<ColumnDefinition Width="15"/>
40+
<ColumnDefinition Width="80"/>
41+
<ColumnDefinition Width="50"/>
42+
</Grid.ColumnDefinitions>
43+
44+
<StackPanel Background="{Binding Item, Converter={StaticResource converter}, ConverterParameter=7}" Height="10" Width="10" Margin="0, -2, 0, 0" Grid.Column="0" Grid.Row="0"/>
45+
<StackPanel Background="{Binding Item, Converter={StaticResource converter}, ConverterParameter=8}" Height="10" Width="10" Margin="0, -2, 0, 0" Grid.Column="0" Grid.Row="1"/>
46+
<StackPanel Background="{Binding Item, Converter={StaticResource converter}, ConverterParameter=9}" Height="10" Width="10" Margin="0, -2, 0, 0" Grid.Column="0" Grid.Row="2"/>
47+
<StackPanel Background="{Binding Item, Converter={StaticResource converter}, ConverterParameter=10}" Height="10" Width="10" Margin="0, -2, 0, 0" Grid.Column="0" Grid.Row="3"/>
48+
<StackPanel Background="{Binding Item, Converter={StaticResource converter}, ConverterParameter=11}" Height="10" Width="10" Margin="0, -2, 0, 0" Grid.Column="0" Grid.Row="4"/>
49+
<StackPanel Background="{Binding Item, Converter={StaticResource converter}, ConverterParameter=12}" Height="10" Width="10" Margin="0, -2, 0, 0" Grid.Column="0" Grid.Row="5"/>
50+
51+
<TextBlock Foreground="Black" Text="Total" Grid.Row="0" Grid.Column="1"/>
52+
<TextBlock Foreground="Black" Text="Under 25" Grid.Row="1" Grid.Column="1"/>
53+
<TextBlock Foreground="Black" Text="Ages 25-64" Grid.Row="2" Grid.Column="1"/>
54+
<TextBlock Foreground="Black" Text="Under 15" Grid.Row="3" Grid.Column="1"/>
55+
<TextBlock Foreground="Black" Text="Under 4" Grid.Row="4" Grid.Column="1"/>
56+
<TextBlock Foreground="Black" Text="Above 65" Grid.Row="5" Grid.Column="1"/>
57+
58+
<TextBlock Foreground="Black" Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=1}" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Center"/>
59+
<TextBlock Foreground="Black" Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=2}" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center"/>
60+
<TextBlock Foreground="Black" Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=3}" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Center"/>
61+
<TextBlock Foreground="Black" Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=4}" Grid.Column="2" Grid.Row="3" HorizontalAlignment="Center"/>
62+
<TextBlock Foreground="Black" Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=5}" Grid.Column="2" Grid.Row="4" HorizontalAlignment="Center"/>
63+
<TextBlock Foreground="Black" Text="{Binding Item, Converter={StaticResource converter}, ConverterParameter=6}" Grid.Column="2" Grid.Row="5" HorizontalAlignment="Center"/>
64+
</Grid>
65+
</StackPanel>
66+
</Border>
67+
68+
</DataTemplate>
69+
70+
</sync:SfChart.Resources>
71+
72+
<sync:SfChart.Header>
73+
<Border BorderBrush="White" Margin="0, 0, 0, 10">
74+
<StackPanel Orientation="Horizontal" Margin="-20, 0, 0, 0">
75+
<Grid>
76+
<Ellipse Width="5" Height="5" Fill="Gray" Margin="0.5, 15, 0, 0"/>
77+
<Path Margin="0,35,0,0" Data="{Binding PathData1}" Stretch="Uniform" Stroke="Gray" StrokeThickness="1"
78+
Fill="Gray" Width="40" Height="18" RenderTransformOrigin="0.5,0.5"/>
79+
</Grid>
80+
<Path Margin="-19,-8,0,0" Data="{Binding PathData}" Stretch="Uniform"
81+
Fill="Gray" Width="60" Height="60" RenderTransformOrigin="0.5,0.5"/>
82+
<StackPanel>
83+
<TextBlock FontSize="22" Margin="5, 0, 0, 0" Text="Global Population by Age Group" FontWeight="Bold"/>
84+
<TextBlock FontSize="13" Margin="5, 0, 0, 0" Text="Exploring Population Trends from 1950 to 2023 and Future Projections to 2100." FontWeight="Medium" Foreground="Gray"/>
85+
</StackPanel>
86+
</StackPanel>
87+
</Border>
88+
</sync:SfChart.Header>
89+
90+
<sync:SfChart.PrimaryAxis>
91+
<sync:NumericalAxis ShowGridLines="False" PlotOffsetEnd="5">
92+
<sync:NumericalAxis.StripLines>
93+
<sync:ChartStripLine Start="2024" Width="100" Background="#dbd9d9" Opacity="0.2"/>
94+
</sync:NumericalAxis.StripLines>
95+
</sync:NumericalAxis>
96+
</sync:SfChart.PrimaryAxis>
97+
98+
<sync:SfChart.SecondaryAxis>
99+
<sync:NumericalAxis Interval="2000000000" LabelCreated="NumericalAxis_LabelCreated_1"/>
100+
</sync:SfChart.SecondaryAxis>
101+
102+
<sync:SfChart.Behaviors>
103+
<sync:ChartTrackBallBehavior/>
104+
</sync:SfChart.Behaviors>
105+
106+
<sync:FastLineSeries x:Name="series" ShowTrackballInfo="False" ItemsSource="{Binding HistoricalPopulationData}" XBindingPath="Year" YBindingPath="TotalPopulation"/>
107+
<sync:FastLineSeries x:Name="series1" ShowTrackballInfo="True" ItemsSource="{Binding HistoricalPopulationData}" XBindingPath="Year" YBindingPath="Under25" TrackBallLabelTemplate="{StaticResource labelTemplate}"/>
108+
<sync:FastLineSeries x:Name="series2" ShowTrackballInfo="False" ItemsSource="{Binding HistoricalPopulationData}" XBindingPath="Year" YBindingPath="Between25to64"/>
109+
<sync:FastLineSeries x:Name="series3" ShowTrackballInfo="False" ItemsSource="{Binding HistoricalPopulationData}" XBindingPath="Year" YBindingPath="Under15"/>
110+
<sync:FastLineSeries x:Name="series4" ShowTrackballInfo="False" ItemsSource="{Binding HistoricalPopulationData}" XBindingPath="Year" YBindingPath="Under4"/>
111+
<sync:FastLineSeries x:Name="series5" ShowTrackballInfo="False" ItemsSource="{Binding HistoricalPopulationData}" XBindingPath="Year" YBindingPath="Above65"/>
112+
113+
<sync:FastLineSeries x:Name="series6" ShowTrackballInfo="False" ItemsSource="{Binding ForecastPopulationData }" XBindingPath="Year" YBindingPath="TotalPopulation"/>
114+
<sync:FastLineSeries x:Name="series7" ShowTrackballInfo="True" ItemsSource="{Binding ForecastPopulationData }" XBindingPath="Year" YBindingPath="Under25" TrackBallLabelTemplate="{StaticResource labelTemplate}"/>
115+
<sync:FastLineSeries x:Name="series8" ShowTrackballInfo="False" ItemsSource="{Binding ForecastPopulationData }" XBindingPath="Year" YBindingPath="Between25to64"/>
116+
<sync:FastLineSeries x:Name="series9" ShowTrackballInfo="False" ItemsSource="{Binding ForecastPopulationData }" XBindingPath="Year" YBindingPath="Under15"/>
117+
<sync:FastLineSeries x:Name="series10" ShowTrackballInfo="False" ItemsSource="{Binding ForecastPopulationData }" XBindingPath="Year" YBindingPath="Under4"/>
118+
<sync:FastLineSeries x:Name="series11" ShowTrackballInfo="False" ItemsSource="{Binding ForecastPopulationData }" XBindingPath="Year" YBindingPath="Above65"/>
119+
120+
</sync:SfChart>
121+
122+
</Border>
123+
</Window>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using Syncfusion.UI.Xaml.Charts;
2+
using System.Globalization;
3+
using System.Text;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Data;
7+
using System.Windows.Documents;
8+
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Navigation;
12+
using System.Windows.Shapes;
13+
14+
namespace ForecastFastLineChart
15+
{
16+
/// <summary>
17+
/// Interaction logic for MainWindow.xaml
18+
/// </summary>
19+
public partial class MainWindow : Window
20+
{
21+
public MainWindow()
22+
{
23+
InitializeComponent();
24+
25+
var model = viewModel.HistoricalPopulationData[0];
26+
series.Interior = series6.Interior = model.Brush1;
27+
series7.Interior = series1.Interior = model.Brush2;
28+
series8.Interior = series2.Interior = model.Brush3;
29+
series9.Interior = series3.Interior = model.Brush4;
30+
series10.Interior = series4.Interior = model.Brush5;
31+
series11.Interior = series5.Interior = model.Brush6;
32+
series6.StrokeDashArray = new System.Windows.Media.DoubleCollection { 10, 3, 2, 3 };
33+
series7.StrokeDashArray = series8.StrokeDashArray = series9.StrokeDashArray = series10.StrokeDashArray = series11.StrokeDashArray = series6.StrokeDashArray;
34+
}
35+
36+
private void NumericalAxis_LabelCreated_1(object sender, LabelCreatedEventArgs e)
37+
{
38+
if (e.AxisLabel is ChartAxisLabel label && label.LabelContent is string content && content != "0")
39+
{
40+
var value = double.Parse(content) / 1000000000;
41+
label.LabelContent = value.ToString() + "B";
42+
}
43+
}
44+
}
45+
46+
public class TooltipValueConverter : IValueConverter
47+
{
48+
private const double Billion = 1000000000;
49+
private const double Million = 1000000;
50+
51+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
52+
{
53+
if (value is Model model && parameter is string para && !string.IsNullOrEmpty(para))
54+
{
55+
switch (para)
56+
{
57+
case "1":
58+
return FormatPopulation(model.TotalPopulation, Billion, "B", 2);
59+
case "2":
60+
return FormatPopulation(model.Under25, Billion, "B", 2);
61+
case "3":
62+
return FormatPopulation(model.Between25to64, Billion, "B", 2);
63+
case "4":
64+
return FormatPopulation(model.Under15, Billion, "B", 2);
65+
case "5":
66+
return FormatPopulation(model.Under4, Million, "M", 3);
67+
case "6":
68+
return FormatPopulation(model.Above65, Million, "M", 2);
69+
case "0":
70+
return $"Population in {model.Year}";
71+
case "7":
72+
return model.Brush1;
73+
case "8":
74+
return model.Brush2;
75+
case "9":
76+
return model.Brush3;
77+
case "10":
78+
return model.Brush4;
79+
case "11":
80+
return model.Brush5;
81+
case "12":
82+
return model.Brush6;
83+
default:
84+
return value;
85+
}
86+
}
87+
88+
return value;
89+
}
90+
91+
private string FormatPopulation(double population, double divisor, string unit, int decimalPlaces)
92+
{
93+
return Math.Round(population / divisor, decimalPlaces) + unit;
94+
}
95+
96+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
97+
{
98+
return value;
99+
}
100+
}
101+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Windows.Media;
2+
3+
namespace ForecastFastLineChart
4+
{
5+
public class Model
6+
{
7+
public double Year { get; set; }
8+
public double TotalPopulation { get; set; }
9+
public double Under25 { get; set; }
10+
public double Between25to64 { get; set; }
11+
public double Under15 { get; set; }
12+
public double Under4 { get; set; }
13+
public double Above65 { get; set; }
14+
15+
public Brush Brush1 = new SolidColorBrush(Colors.BlueViolet);
16+
public Brush Brush2 = new SolidColorBrush(Colors.Green);
17+
public Brush Brush3 = new SolidColorBrush(Colors.Brown);
18+
public Brush Brush4 = new SolidColorBrush(Colors.DeepPink);
19+
public Brush Brush5 = new SolidColorBrush(Colors.DarkBlue);
20+
public Brush Brush6 = new SolidColorBrush(Colors.Orange);
21+
22+
public Model(double year, double totalPopulation, double under25, double between25to64, double under15, double under4, double above65)
23+
{
24+
Year = year;
25+
TotalPopulation = totalPopulation;
26+
Under25 = under25;
27+
Between25to64 = between25to64;
28+
Under15 = under15;
29+
Under4 = under4;
30+
Above65 = above65;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)