Skip to content

Commit 02912c0

Browse files
Merge pull request #1 from SyncfusionExamples/T578711-Performance-Analysis-of-.NET-MAUI-charts
T578711 - Performance Analysis of .NET MAUI charts
2 parents 8036f1d + ae40f71 commit 02912c0

39 files changed

+1231
-2
lines changed

PerformanceMetrics/App.xaml

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:PerformanceMetrics"
5+
x:Class="PerformanceMetrics.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>

PerformanceMetrics/App.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace PerformanceMetrics
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}

PerformanceMetrics/AppShell.xaml

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="PerformanceMetrics.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:PerformanceMetrics"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="PerformanceMetrics">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>

PerformanceMetrics/AppShell.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PerformanceMetrics
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}

PerformanceMetrics/DataGenerator.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace PerformanceMetrics
10+
{
11+
public class DataGenerator : INotifyPropertyChanged
12+
{
13+
public DateTime StartTime { get; set; }
14+
15+
public bool IsRunning { get; set; }
16+
17+
public string timeTaken = "Time Taken: 0 ms";
18+
19+
private bool isActive = false;
20+
21+
public bool IsActive
22+
{
23+
get { return isActive; }
24+
set
25+
{
26+
if (isActive != value)
27+
{
28+
isActive = value;
29+
OnPropertyChanged(nameof(IsActive));
30+
}
31+
}
32+
}
33+
34+
private bool isVisible = false;
35+
36+
public bool IsVisible
37+
{
38+
get { return !IsActive; }
39+
set
40+
{
41+
if (isVisible != value)
42+
{
43+
isVisible = value;
44+
OnPropertyChanged(nameof(IsVisible));
45+
}
46+
}
47+
}
48+
49+
public string TimeTaken
50+
{
51+
get
52+
{
53+
return timeTaken;
54+
}
55+
set
56+
{
57+
timeTaken = value;
58+
OnPropertyChanged(nameof(TimeTaken));
59+
}
60+
}
61+
62+
Random random;
63+
64+
public DataGenerator()
65+
{
66+
random = new Random();
67+
}
68+
69+
public event PropertyChangedEventHandler? PropertyChanged;
70+
71+
public ObservableCollection<Model> LoadData(int count)
72+
{
73+
ObservableCollection<Model> data = new ObservableCollection<Model>();
74+
75+
double value = 50;
76+
77+
for (int i = 0; i < count; i++)
78+
{
79+
data.Add(new Model() { XValue = i, YValue = value });
80+
81+
if (random.NextDouble() > .5)
82+
{
83+
value += random.NextDouble();
84+
}
85+
else
86+
{
87+
value -= random.NextDouble();
88+
}
89+
}
90+
91+
return data;
92+
}
93+
94+
protected void OnPropertyChanged(string propertyName)
95+
{
96+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
97+
}
98+
}
99+
}

PerformanceMetrics/MainPage.xaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:shimmer="clr-namespace:Syncfusion.Maui.Shimmer;assembly=Syncfusion.Maui.Core"
5+
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
6+
xmlns:local="clr-namespace:PerformanceMetrics"
7+
x:Class="PerformanceMetrics.MainPage">
8+
9+
<Grid RowSpacing="10">
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="*"/>
12+
<RowDefinition Height="9*"/>
13+
</Grid.RowDefinitions>
14+
15+
<Grid.BindingContext>
16+
<local:DataGenerator/>
17+
</Grid.BindingContext>
18+
<HorizontalStackLayout Grid.Row="0" Spacing="5">
19+
<Button Text="Load 10K Data" Clicked="Button_Clicked"/>
20+
<Button Text="Load 50K Data" Clicked="Button_Clicked_1"/>
21+
<Button Text="Load 100K Data" Clicked="Button_Clicked_2"/>
22+
<Label Text="{Binding TimeTaken,Mode=TwoWay}" TextColor="Black" Margin="2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontAttributes="Bold" FontFamily="Helvicta"/>
23+
</HorizontalStackLayout>
24+
<ActivityIndicator Grid.Row="1" IsRunning="{Binding IsActive,Mode=TwoWay}" ZIndex="2">
25+
</ActivityIndicator>
26+
<chart:SfCartesianChart x:Name="myChart" Grid.Row="1" ZIndex="1">
27+
<chart:SfCartesianChart.XAxes>
28+
<chart:NumericalAxis/>
29+
</chart:SfCartesianChart.XAxes>
30+
<chart:SfCartesianChart.YAxes>
31+
<chart:NumericalAxis/>
32+
</chart:SfCartesianChart.YAxes>
33+
<chart:SfCartesianChart.TrackballBehavior>
34+
<chart:ChartTrackballBehavior/>
35+
</chart:SfCartesianChart.TrackballBehavior>
36+
<local:FastLineSeriesExt XBindingPath="XValue" EnableAntiAliasing="False" YBindingPath="YValue" x:Name="mySeries1"/>
37+
</chart:SfCartesianChart>
38+
39+
</Grid>
40+
</ContentPage>

PerformanceMetrics/MainPage.xaml.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using Syncfusion.Maui.Charts;
2+
using System.Collections.ObjectModel;
3+
using System.Globalization;
4+
5+
namespace PerformanceMetrics
6+
{
7+
public partial class MainPage : ContentPage
8+
{
9+
public MainPage()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private void Button_Clicked(object sender, EventArgs e)
15+
{
16+
var button = sender as Button;
17+
if (button != null && button.BindingContext is DataGenerator generator)
18+
{
19+
ObservableCollection<Model> data = new ObservableCollection<Model>();
20+
data = generator.LoadData(10000);
21+
generator.IsActive = true;
22+
generator.StartTime = DateTime.Now;
23+
generator.IsRunning = true;
24+
mySeries1.ItemsSource = data;
25+
}
26+
}
27+
28+
private void Button_Clicked_1(object sender, EventArgs e)
29+
{
30+
var button = sender as Button;
31+
if (button != null && button.BindingContext is DataGenerator generator)
32+
{
33+
ObservableCollection<Model> data = new ObservableCollection<Model>();
34+
data = generator.LoadData(50000);
35+
generator.IsActive = true;
36+
generator.StartTime = DateTime.Now;
37+
generator.IsRunning = true;
38+
mySeries1.ItemsSource = data;
39+
}
40+
}
41+
42+
private void Button_Clicked_2(object sender, EventArgs e)
43+
{
44+
var button = sender as Button;
45+
if (button != null && button.BindingContext is DataGenerator generator)
46+
{
47+
ObservableCollection<Model> data = new ObservableCollection<Model>();
48+
data = generator.LoadData(100000);
49+
generator.IsActive = true;
50+
generator.StartTime = DateTime.Now;
51+
generator.IsRunning = true;
52+
mySeries1.ItemsSource = data;
53+
}
54+
55+
}
56+
}
57+
58+
public class Model
59+
{
60+
public double XValue { get; set; }
61+
public double YValue { get; set; }
62+
}
63+
64+
public class FastLineSeriesExt : FastLineSeries
65+
{
66+
protected override void DrawSeries(ICanvas canvas, ReadOnlyObservableCollection<ChartSegment> segments, RectF clipRect)
67+
{
68+
base.DrawSeries(canvas, segments, clipRect);
69+
70+
if (this.BindingContext is DataGenerator generator)
71+
{
72+
if (generator.IsActive)
73+
{
74+
TimeSpan timeTaken = DateTime.Now.Subtract(generator.StartTime);
75+
generator.IsActive = false;
76+
generator.TimeTaken = "Time Taken: " + timeTaken.TotalMilliseconds.ToString() + "ms";
77+
generator.IsRunning = false;
78+
}
79+
}
80+
}
81+
}
82+
}

PerformanceMetrics/MauiProgram.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace PerformanceMetrics
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>PerformanceMetrics</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>PerformanceMetrics</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.performancemetrics</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
34+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
35+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
37+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
39+
</PropertyGroup>
40+
41+
<ItemGroup>
42+
<!-- App Icon -->
43+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
44+
45+
<!-- Splash Screen -->
46+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
47+
48+
<!-- Images -->
49+
<MauiImage Include="Resources\Images\*" />
50+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
51+
52+
<!-- Custom Fonts -->
53+
<MauiFont Include="Resources\Fonts\*" />
54+
55+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
56+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
57+
</ItemGroup>
58+
59+
<ItemGroup>
60+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
61+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
62+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
63+
<PackageReference Include="Syncfusion.Maui.Charts" Version="25.1.39" />
64+
</ItemGroup>
65+
66+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5+
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
6+
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
8+
<DefaultDevice>pixel_xl_-_api_33</DefaultDevice>
9+
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
11+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
12+
</PropertyGroup>
13+
</Project>

0 commit comments

Comments
 (0)