Skip to content

Commit ff2586e

Browse files
Merge pull request #2 from SyncfusionExamples/Add-Legend
Prepared sample and read me file
2 parents 9843ecb + c8487b4 commit ff2586e

39 files changed

+9152
-0
lines changed

ChartSample/ChartSample.sln

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.35521.163 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChartSample", "ChartSample\ChartSample.csproj", "{FD742847-10DC-4BE6-9D6F-619BC71F6B16}"
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+
{FD742847-10DC-4BE6-9D6F-619BC71F6B16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FD742847-10DC-4BE6-9D6F-619BC71F6B16}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FD742847-10DC-4BE6-9D6F-619BC71F6B16}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FD742847-10DC-4BE6-9D6F-619BC71F6B16}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

ChartSample/ChartSample/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:ChartSample"
5+
x:Class="ChartSample.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 ChartSample
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 AppShell());
13+
}
14+
}
15+
}
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+
<Shell
3+
x:Class="ChartSample.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:ChartSample"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="ChartSample">
9+
10+
<ShellContent
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ChartSample
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.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);net9.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>ChartSample</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>ChartSample</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.chartsample</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
34+
<WindowsPackageType>None</WindowsPackageType>
35+
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
42+
</PropertyGroup>
43+
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.30" />
64+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
65+
<PackageReference Include="Syncfusion.Maui.Charts" Version="*" />
66+
</ItemGroup>
67+
68+
</Project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
5+
xmlns:local="clr-namespace:ChartSample"
6+
x:Class="ChartSample.MainPage">
7+
8+
<ContentPage.BindingContext>
9+
<local:ViewModel/>
10+
</ContentPage.BindingContext>
11+
12+
<chart:SfCartesianChart x:Name="chart">
13+
14+
<chart:SfCartesianChart.Title>
15+
<Label Text="Blood Type Distribution Among Population" FontAttributes="Bold" HorizontalTextAlignment="Center" FontSize="16" />
16+
</chart:SfCartesianChart.Title>
17+
18+
<chart:SfCartesianChart.XAxes>
19+
<chart:CategoryAxis PlotOffsetStart="5" PlotOffsetEnd="5"/>
20+
</chart:SfCartesianChart.XAxes>
21+
22+
<chart:SfCartesianChart.YAxes>
23+
<chart:NumericalAxis PlotOffsetEnd="10">
24+
<chart:NumericalAxis.LabelStyle>
25+
<chart:ChartAxisLabelStyle LabelFormat="0'%"/>
26+
</chart:NumericalAxis.LabelStyle>
27+
</chart:NumericalAxis>
28+
</chart:SfCartesianChart.YAxes>
29+
30+
<chart:SfCartesianChart.Legend>
31+
<chart:ChartLegend>
32+
<chart:ChartLegend.ItemTemplate>
33+
<DataTemplate>
34+
<StackLayout Orientation="Horizontal">
35+
<Rectangle HeightRequest="7" Margin="10"
36+
WidthRequest="20" Background="{Binding IconBrush}"/>
37+
<Label Text="{Binding Text}" Margin="3"/>
38+
</StackLayout>
39+
</DataTemplate>
40+
</chart:ChartLegend.ItemTemplate>
41+
</chart:ChartLegend>
42+
</chart:SfCartesianChart.Legend>
43+
44+
<chart:StackingLineSeries ItemsSource="{Binding BloodType}" Label="O+"
45+
XBindingPath="Country" YBindingPath="OType"
46+
Fill="DodgerBlue" ShowMarkers="True"
47+
LegendIcon="SeriesType"/>
48+
49+
<chart:StackingLineSeries ItemsSource="{Binding BloodType}" Label="A+"
50+
XBindingPath="Country" YBindingPath="AType"
51+
Fill="Orange" ShowMarkers="True"
52+
LegendIcon="SeriesType"/>
53+
54+
<chart:StackingLineSeries ItemsSource="{Binding BloodType}" Label="B+"
55+
XBindingPath="Country" YBindingPath="BType"
56+
Fill="Green" ShowMarkers="True"
57+
LegendIcon="SeriesType"/>
58+
</chart:SfCartesianChart>
59+
60+
</ContentPage>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace ChartSample
4+
{
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
13+
public class Model
14+
{
15+
public string Country { get; set; }
16+
public double OType { get; set; }
17+
public double AType { get; set; }
18+
public double BType { get; set; }
19+
public Model(string country, double otype, double atype, double btype)
20+
{
21+
Country = country;
22+
OType = otype;
23+
AType = atype;
24+
BType = btype;
25+
}
26+
}
27+
28+
public class ViewModel
29+
{
30+
public ObservableCollection<Model> BloodType { get; set; }
31+
public ViewModel()
32+
{
33+
BloodType = new ObservableCollection<Model>()
34+
{
35+
new Model("US",37.40,35.70,8.50),
36+
new Model("Switzerland",26,37,13),
37+
new Model("Austria",30,33,12),
38+
new Model("Bulgaria",28,37,13),
39+
new Model("Poland",26.60,31.26,15.73),
40+
new Model("Myanmar",35.70,23.80,32.70),
41+
};
42+
}
43+
}
44+
}
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 ChartSample
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>

0 commit comments

Comments
 (0)