Skip to content

Commit cbafb1d

Browse files
Merge pull request #1 from SyncfusionExamples/Update-blog-sample-and-readme
Updated blog Sample and readme
2 parents 74c4ab5 + ebb6542 commit cbafb1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+25346
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1-
# Stacked-area-chart-for-GDP-Analysis-using-Syncfusion-MAUI-Toolkit
1+
# Stacked area chart for GDP Analysis using Syncfusion MAUI Toolkit
22
This sample demonstrates how to create a stacked area chart for GDP analysis using Syncfusion MAUI Toolkit. Enhance data visualization with interactive features like series highlighting, customized trackball, and data grid integration for seamless user insights.
3+
4+
### Introduction
5+
Effectively analyzing multi-series data in charts can be challenging, especially when multiple series overlap or have closely placed data points. Highlighting a series based on user interaction allows users to focus on a specific data series, improving clarity and making comparisons more intuitive. This enhances the user experience by reducing visual clutter and making key trends stand out.
6+
7+
### Key Features
8+
• Highlighting a series when interacting with the chart.<br>
9+
• Dynamically updating a DataGrid to reflect the selected data segment.</br>
10+
• Synchronizing the trackball and DataGrid to highlight relevant data. <br>
11+
• Programmatically triggering the trackball from the DataGrid.</br>
12+
• Exporting the chart as an image for easy sharing and reporting.<br>
13+
• Dynamically changing the continent selection, updating the chart data accordingly.</br>
14+
15+
## Troubleshooting
16+
17+
### Path Too Long Exception
18+
19+
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.
20+
21+
For a step-by-step procedure, refer to [Stacked area chart for GDP Analysis blog using Syncfusion MAUI Toolkit]().
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackedAreaChart", "StackedAreaChart\StackedAreaChart.csproj", "{549A2952-48B3-412A-B6A9-6D45721DE939}"
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+
{549A2952-48B3-412A-B6A9-6D45721DE939}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{549A2952-48B3-412A-B6A9-6D45721DE939}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{549A2952-48B3-412A-B6A9-6D45721DE939}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{549A2952-48B3-412A-B6A9-6D45721DE939}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
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+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:StackedAreaChart"
5+
x:Class="StackedAreaChart.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace StackedAreaChart
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new MainPage());
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="StackedAreaChart.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:StackedAreaChart"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="StackedAreaChart">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace StackedAreaChart
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using Syncfusion.Maui.Toolkit.Charts;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace StackedAreaChart
10+
{
11+
public class InteractionExt : ChartInteractiveBehavior
12+
{
13+
protected override void OnTouchMove(ChartBase chart, float pointX, float pointY)
14+
{
15+
base.OnTouchMove(chart, pointX, pointY);
16+
bool isSeriesTouched = false;
17+
18+
if (chart is SfCartesianChart stackedAreaChart)
19+
{
20+
var series = stackedAreaChart.Series;
21+
22+
for (int i = 0; i < series.Count; i++)
23+
{
24+
var seriesItem = series[i];
25+
26+
if (seriesItem != null)
27+
{
28+
var index = seriesItem.GetDataPointIndex(pointX, pointY);
29+
30+
if (index != -1)
31+
{
32+
seriesItem.Opacity = 1;
33+
isSeriesTouched = true;
34+
}
35+
else
36+
{
37+
seriesItem.Opacity = 0.33;
38+
}
39+
}
40+
}
41+
42+
if (!isSeriesTouched)
43+
{
44+
foreach (var item in series)
45+
{
46+
item.Opacity = 1;
47+
}
48+
}
49+
}
50+
}
51+
}
52+
53+
public class TrackballExt : ChartTrackballBehavior
54+
{
55+
protected override void LabelsGenerated(List<TrackballPointInfo> pointInfos)
56+
{
57+
foreach (var item in pointInfos)
58+
{
59+
var series = item.Series;
60+
61+
if (series is StackingAreaSeries stackingArea && stackingArea.YBindingPath != "NorthAmerica")
62+
{
63+
item.Label = string.Empty;
64+
}
65+
66+
item.MarkerSettings = new ChartMarkerSettings() { Fill = Colors.White, Stroke = series.Fill, StrokeWidth = 2 };
67+
}
68+
}
69+
}
70+
71+
public class TrackballLabelConverter : IValueConverter
72+
{
73+
private static readonly Dictionary<string, Func<Model, double>> DataSelectors = new()
74+
{
75+
{ "0", m => m.Oceania },
76+
{ "1", m => m.EasternEurope },
77+
{ "2", m => m.Africa },
78+
{ "3", m => m.SouthAmerica },
79+
{ "4", m => m.NorthAmerica },
80+
{ "5", m => m.WesternEurope },
81+
{ "6", m => m.Asia },
82+
{ "7", m => m.Total }
83+
};
84+
85+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
86+
{
87+
if (value is not TrackballPointInfo pointInfo || parameter is not string para)
88+
return null;
89+
90+
if (pointInfo.DataItem is Model model && DataSelectors.TryGetValue(para, out var selector))
91+
{
92+
double yValue = selector(model);
93+
return $"{Math.Round(yValue, 2)}%";
94+
}
95+
96+
return null;
97+
}
98+
99+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
100+
{
101+
throw new NotImplementedException();
102+
}
103+
}
104+
105+
public class TrackballColorConverter : IValueConverter
106+
{
107+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
108+
{
109+
if (value is not TrackballPointInfo pointInfo || parameter is not string para)
110+
return null;
111+
112+
if (pointInfo.Series.BindingContext is ViewModel viewModel
113+
&& int.TryParse(para, out int index)
114+
&& index >= 0 && index < viewModel.PaletteBrushes.Count)
115+
{
116+
return ((SolidColorBrush)viewModel.PaletteBrushes[index]).Color;
117+
}
118+
119+
return null;
120+
}
121+
122+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
123+
{
124+
throw new NotImplementedException();
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)