Skip to content

Commit 9cef33a

Browse files
Merge pull request #1 from SyncfusionExamples/image_category
Task 894979 Add Images in axis line in .NET MAUI Cartesian Chart
2 parents ba1aec2 + bc0f055 commit 9cef33a

Some content is hidden

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

52 files changed

+1293
-2
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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>AddImageInCategoryAxis</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>AddImageInCategoryAxis</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.addimageincategoryaxis</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+
<MauiImage Remove="Resources\Images\canada.png" />
61+
<MauiImage Remove="Resources\Images\china.png" />
62+
<MauiImage Remove="Resources\Images\france.png" />
63+
<MauiImage Remove="Resources\Images\germany.png" />
64+
<MauiImage Remove="Resources\Images\india.png" />
65+
<MauiImage Remove="Resources\Images\japan.png" />
66+
<MauiImage Remove="Resources\Images\netherlands.png" />
67+
<MauiImage Remove="Resources\Images\southkorea.png" />
68+
<MauiImage Remove="Resources\Images\spain.png" />
69+
<MauiImage Remove="Resources\Images\uk.png" />
70+
<MauiImage Remove="Resources\Images\us.png" />
71+
</ItemGroup>
72+
73+
<ItemGroup>
74+
<None Remove="Resources\Images\canada.png" />
75+
<None Remove="Resources\Images\china.png" />
76+
<None Remove="Resources\Images\flag.png" />
77+
<None Remove="Resources\Images\france.png" />
78+
<None Remove="Resources\Images\germany.png" />
79+
<None Remove="Resources\Images\india.png" />
80+
<None Remove="Resources\Images\japan.png" />
81+
<None Remove="Resources\Images\netherlands.png" />
82+
<None Remove="Resources\Images\southkorea.png" />
83+
<None Remove="Resources\Images\spain.png" />
84+
<None Remove="Resources\Images\uk.png" />
85+
<None Remove="Resources\Images\us.png" />
86+
</ItemGroup>
87+
88+
<ItemGroup>
89+
<EmbeddedResource Include="Resources\Images\canada.png" />
90+
<EmbeddedResource Include="Resources\Images\china.png" />
91+
<EmbeddedResource Include="Resources\Images\france.png" />
92+
<EmbeddedResource Include="Resources\Images\germany.png" />
93+
<EmbeddedResource Include="Resources\Images\india.png" />
94+
<EmbeddedResource Include="Resources\Images\japan.png" />
95+
<EmbeddedResource Include="Resources\Images\netherlands.png" />
96+
<EmbeddedResource Include="Resources\Images\southkorea.png" />
97+
<EmbeddedResource Include="Resources\Images\spain.png" />
98+
<EmbeddedResource Include="Resources\Images\uk.png" />
99+
<EmbeddedResource Include="Resources\Images\us.png" />
100+
</ItemGroup>
101+
102+
<ItemGroup>
103+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
104+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
105+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
106+
<PackageReference Include="Syncfusion.Maui.Charts" Version="*" />
107+
</ItemGroup>
108+
109+
</Project>
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+
<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_5_-_api_34</DefaultDevice>
9+
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
11+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
12+
</PropertyGroup>
13+
<PropertyGroup Condition="'$(TargetPlatformIdentifier)'=='iOS'">
14+
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
15+
<PlatformTarget>arm64</PlatformTarget>
16+
</PropertyGroup>
17+
<ItemGroup>
18+
<None Update="App.xaml">
19+
<SubType>Designer</SubType>
20+
</None>
21+
<None Update="AppShell.xaml">
22+
<SubType>Designer</SubType>
23+
</None>
24+
<None Update="MainPage.xaml">
25+
<SubType>Designer</SubType>
26+
</None>
27+
<None Update="Platforms\Windows\App.xaml">
28+
<SubType>Designer</SubType>
29+
</None>
30+
<None Update="Platforms\Windows\Package.appxmanifest">
31+
<SubType>Designer</SubType>
32+
</None>
33+
<None Update="Resources\Styles\Colors.xaml">
34+
<SubType>Designer</SubType>
35+
</None>
36+
<None Update="Resources\Styles\Styles.xaml">
37+
<SubType>Designer</SubType>
38+
</None>
39+
</ItemGroup>
40+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.10.34916.146
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddImageInCategoryAxis", "AddImageInCategoryAxis.csproj", "{FD5FC89D-71FD-40AE-A369-F231B04D80D6}"
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+
{FD5FC89D-71FD-40AE-A369-F231B04D80D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FD5FC89D-71FD-40AE-A369-F231B04D80D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FD5FC89D-71FD-40AE-A369-F231B04D80D6}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{FD5FC89D-71FD-40AE-A369-F231B04D80D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{FD5FC89D-71FD-40AE-A369-F231B04D80D6}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{FD5FC89D-71FD-40AE-A369-F231B04D80D6}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {8FF5ED4D-CE72-4325-8F31-E08FFC0118A6}
26+
EndGlobalSection
27+
EndGlobal

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

AddImageInCategoryAxis/App.xaml.cs

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

AddImageInCategoryAxis/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="AddImageInCategoryAxis.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:AddImageInCategoryAxis"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="AddImageInCategoryAxis">
9+
10+
<ShellContent
11+
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 AddImageInCategoryAxis
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}

AddImageInCategoryAxis/MainPage.xaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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:AddImageInCategoryAxis"
6+
x:Class="AddImageInCategoryAxis.MainPage">
7+
8+
<chart:SfCartesianChart BackgroundColor="White" >
9+
10+
<chart:SfCartesianChart.BindingContext>
11+
<local:DataViewModel/>
12+
</chart:SfCartesianChart.BindingContext>
13+
14+
<chart:SfCartesianChart.Title>
15+
<Label Text="Leading Countries by Tourist Arrivals" Margin="30,30,0,10"
16+
FontSize="26" HorizontalOptions="Center"
17+
FontAttributes="Bold"
18+
TextColor="Black"
19+
/>
20+
</chart:SfCartesianChart.Title>
21+
22+
<chart:SfCartesianChart.XAxes>
23+
<local:CustomCategoryAxis LabelsIntersectAction="None" ShowMajorGridLines="False">
24+
<local:CustomCategoryAxis.MajorGridLineStyle>
25+
<chart:ChartLineStyle Stroke="White" StrokeWidth="2"/>
26+
</local:CustomCategoryAxis.MajorGridLineStyle>
27+
<local:CustomCategoryAxis.LabelStyle>
28+
<chart:ChartAxisLabelStyle TextColor="Black"/>
29+
</local:CustomCategoryAxis.LabelStyle>
30+
<local:CustomCategoryAxis.AxisLineStyle>
31+
<chart:ChartLineStyle Stroke="Black" StrokeWidth="1"/>
32+
</local:CustomCategoryAxis.AxisLineStyle>
33+
34+
</local:CustomCategoryAxis>
35+
36+
</chart:SfCartesianChart.XAxes>
37+
38+
<chart:SfCartesianChart.YAxes>
39+
<chart:NumericalAxis Maximum="800" Minimum="0" Interval="100" >
40+
<chart:NumericalAxis.LabelStyle>
41+
<chart:ChartAxisLabelStyle TextColor="Black"/>
42+
</chart:NumericalAxis.LabelStyle>
43+
<chart:NumericalAxis.AxisLineStyle>
44+
<chart:ChartLineStyle Stroke="Black" StrokeWidth="1"/>
45+
</chart:NumericalAxis.AxisLineStyle>
46+
<chart:NumericalAxis.MajorTickStyle>
47+
<chart:ChartAxisTickStyle Stroke="Black" StrokeWidth="1"/>
48+
</chart:NumericalAxis.MajorTickStyle>
49+
</chart:NumericalAxis>
50+
</chart:SfCartesianChart.YAxes>
51+
52+
<chart:SfCartesianChart.ZoomPanBehavior>
53+
<chart:ChartZoomPanBehavior EnablePanning="True"/>
54+
</chart:SfCartesianChart.ZoomPanBehavior>
55+
56+
<chart:ColumnSeries ItemsSource="{Binding Data}"
57+
XBindingPath="Country"
58+
YBindingPath="Vists"
59+
PaletteBrushes="{Binding CustomBrush}" Stroke="Black" StrokeWidth="1"/>
60+
61+
</chart:SfCartesianChart>
62+
63+
</ContentPage>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.Maui.Graphics.Platform;
2+
using Syncfusion.Maui.Charts;
3+
4+
namespace AddImageInCategoryAxis
5+
{
6+
public partial class MainPage : ContentPage
7+
{
8+
public MainPage()
9+
{
10+
InitializeComponent();
11+
}
12+
}
13+
14+
public class CustomCategoryAxis : CategoryAxis
15+
{
16+
protected override void DrawAxis(ICanvas canvas, Rect arrangeRect)
17+
{
18+
base.DrawAxis(canvas, arrangeRect);
19+
20+
foreach (ChartAxisLabel label in VisibleLabels)
21+
{
22+
string labelText = label.Content.ToString();
23+
if (this.BindingContext is DataViewModel viewModel && labelText != null && viewModel.Streams.ContainsKey(labelText))
24+
{
25+
Stream stream = viewModel.Streams[labelText];
26+
var image = PlatformImage.FromStream(stream);
27+
var top = ValueToPoint(label.Position);
28+
canvas.DrawImage(image, top - viewModel.OffsetX, (float)arrangeRect.Height - viewModel.OffsetY , viewModel.Width, viewModel.Height);
29+
}
30+
}
31+
}
32+
}
33+
}

AddImageInCategoryAxis/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 AddImageInCategoryAxis
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder.ConfigureSyncfusionCore();
12+
builder
13+
.UseMauiApp<App>()
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AddImageInCategoryAxis
8+
{
9+
public class DataModel
10+
{
11+
public string Country { get; set; }
12+
public int Vists { get; set; }
13+
}
14+
}
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>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace AddImageInCategoryAxis
6+
{
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
}
11+
}

0 commit comments

Comments
 (0)