Skip to content

Commit 85b597e

Browse files
Merge pull request #1 from SyncfusionExamples/How-to-display-X-and-Y-values-of-trackball-moving-trace-in-Labels-in-.NET-MAUI-Cartesian-Chart-sample
Added KB sample - How to display X and Y values of trackball moving trace in Labels in .NET MAUI Cartesian Chart
2 parents c05a016 + 04575f3 commit 85b597e

39 files changed

+1483
-2
lines changed
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.35027.167
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisplayTrackballValues", "DisplayTrackballValues\DisplayTrackballValues.csproj", "{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}"
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+
{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{CBDBBD45-3C8E-42A5-A282-D1AFC1E0861D}.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 = {3FE2B269-B05B-4E5A-BE28-C1D888F7C384}
26+
EndGlobalSection
27+
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:DisplayTrackballValues"
5+
x:Class="DisplayTrackballValues.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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace DisplayTrackballValues
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}
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="DisplayTrackballValues.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:DisplayTrackballValues"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="DisplayTrackballValues">
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 DisplayTrackballValues
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
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>DisplayTrackballValues</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>DisplayTrackballValues</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.displaytrackballvalues</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="8.0.92" />
61+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.92" />
62+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
63+
<PackageReference Include="Syncfusion.Maui.Charts" Version="*" />
64+
</ItemGroup>
65+
66+
</Project>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
x:Class="DisplayTrackballValues.MainPage"
5+
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
6+
xmlns:local="clr-namespace:DisplayTrackballValues">
7+
8+
<ContentPage.BindingContext>
9+
<local:ViewModel x:Name="viewModel"/>
10+
</ContentPage.BindingContext>
11+
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="8*"/>
15+
<ColumnDefinition Width="2*"/>
16+
</Grid.ColumnDefinitions>
17+
18+
<chart:SfCartesianChart x:Name="chart" Grid.Column="0" TrackballCreated="chart_TrackballCreated">
19+
20+
<chart:SfCartesianChart.Title>
21+
<Label Text="Sales Comparison" ></Label>
22+
</chart:SfCartesianChart.Title>
23+
24+
<chart:SfCartesianChart.XAxes>
25+
<chart:DateTimeAxis Interval="2" EdgeLabelsVisibilityMode="AlwaysVisible"/>
26+
</chart:SfCartesianChart.XAxes>
27+
28+
<chart:SfCartesianChart.YAxes>
29+
<chart:NumericalAxis/>
30+
</chart:SfCartesianChart.YAxes>
31+
32+
<chart:SfCartesianChart.TrackballBehavior>
33+
<chart:ChartTrackballBehavior ShowLabel="False"/>
34+
</chart:SfCartesianChart.TrackballBehavior>
35+
36+
<chart:SfCartesianChart.Legend>
37+
<chart:ChartLegend/>
38+
</chart:SfCartesianChart.Legend>
39+
40+
<chart:LineSeries ItemsSource="{Binding ProductSalesDetails}"
41+
x:Name="series1"
42+
XBindingPath="Date"
43+
YBindingPath="ProductASales"
44+
StrokeWidth="3"
45+
ShowTrackballLabel="True"
46+
Label="Product A"
47+
Fill="RoyalBlue"/>
48+
<chart:LineSeries ItemsSource="{Binding ProductSalesDetails}"
49+
x:Name="series2"
50+
XBindingPath="Date"
51+
YBindingPath="ProductBSales"
52+
StrokeWidth="3"
53+
ShowTrackballLabel="True"
54+
Label="Product B"
55+
Fill="HotPink"/>
56+
<chart:LineSeries ItemsSource="{Binding ProductSalesDetails}"
57+
x:Name="series3"
58+
XBindingPath="Date"
59+
YBindingPath="ProductCSales"
60+
StrokeWidth="3"
61+
ShowTrackballLabel="True"
62+
Label="Product C"
63+
Fill="Green"/>
64+
65+
</chart:SfCartesianChart>
66+
<VerticalStackLayout Grid.Column="1" HorizontalOptions="Center">
67+
<Label HorizontalOptions="Center" Text="Trackball Values" FontAttributes="Bold"/>
68+
<VerticalStackLayout>
69+
<Frame Background="LightBlue" CornerRadius="8" Margin="5" BorderColor="Gray">
70+
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
71+
<Label x:Name="dateLabel1"
72+
FontSize="14"
73+
FontAttributes="Bold"
74+
TextColor="Black"
75+
VerticalOptions="Center"/>
76+
<Label Text=" : "
77+
FontSize="14"
78+
FontAttributes="Bold"
79+
TextColor="Black"
80+
VerticalOptions="Center"/>
81+
<Label x:Name="valueLabel1"
82+
FontSize="14"
83+
FontAttributes="Bold"
84+
TextColor="Black"
85+
VerticalOptions="Center"/>
86+
</HorizontalStackLayout>
87+
</Frame>
88+
</VerticalStackLayout>
89+
<VerticalStackLayout>
90+
<Frame Background="Pink" CornerRadius="8" Margin="5" BorderColor="Gray">
91+
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
92+
<Label x:Name="dateLabel2"
93+
FontSize="14"
94+
FontAttributes="Bold"
95+
TextColor="Black"
96+
VerticalOptions="Center"/>
97+
<Label Text=" : "
98+
FontSize="14"
99+
FontAttributes="Bold"
100+
TextColor="Black"
101+
VerticalOptions="Center"/>
102+
<Label x:Name="valueLabel2"
103+
FontSize="14"
104+
FontAttributes="Bold"
105+
TextColor="Black"
106+
VerticalOptions="Center"/>
107+
</HorizontalStackLayout>
108+
</Frame>
109+
</VerticalStackLayout>
110+
<VerticalStackLayout>
111+
<Frame Background="LightGreen" CornerRadius="8" Margin="5" BorderColor="Gray">
112+
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
113+
<Label x:Name="dateLabel3"
114+
FontSize="14"
115+
FontAttributes="Bold"
116+
TextColor="Black"
117+
VerticalOptions="Center"/>
118+
<Label Text=" : "
119+
FontSize="14"
120+
FontAttributes="Bold"
121+
TextColor="Black"
122+
VerticalOptions="Center"/>
123+
<Label x:Name="valueLabel3"
124+
FontSize="14"
125+
FontAttributes="Bold"
126+
TextColor="Black"
127+
VerticalOptions="Center"/>
128+
</HorizontalStackLayout>
129+
</Frame>
130+
</VerticalStackLayout>
131+
</VerticalStackLayout>
132+
</Grid>
133+
134+
</ContentPage>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Syncfusion.Maui.Charts;
2+
3+
namespace DisplayTrackballValues
4+
{
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
private void chart_TrackballCreated(object sender, TrackballEventArgs e)
13+
{
14+
var items = e.TrackballPointsInfo;
15+
16+
foreach (var item in items)
17+
{
18+
var series = item.Series;
19+
20+
if (series == series1)
21+
{
22+
item.MarkerSettings = new ChartMarkerSettings()
23+
{
24+
Fill = Colors.DeepSkyBlue,
25+
Width = 15,
26+
Height = 15,
27+
Stroke = Colors.RoyalBlue,
28+
StrokeWidth = 3,
29+
Type = ShapeType.InvertedTriangle
30+
};
31+
32+
dateLabel1.SetBinding(Label.TextProperty, new Binding("Date") { Source = item.DataItem, StringFormat = "{0:dd/MM/yyyy}" });
33+
valueLabel1.SetBinding(Label.TextProperty, new Binding("Label") { Source = item });
34+
}
35+
36+
else if (series == series2)
37+
{
38+
item.MarkerSettings = new ChartMarkerSettings()
39+
{
40+
Fill = Colors.LightPink,
41+
Width = 15,
42+
Height = 15,
43+
Stroke = Colors.HotPink,
44+
StrokeWidth = 3,
45+
Type = ShapeType.Cross
46+
};
47+
48+
dateLabel2.SetBinding(Label.TextProperty, new Binding("Date") { Source = item.DataItem, StringFormat = "{0:dd/MM/yyyy}" });
49+
valueLabel2.SetBinding(Label.TextProperty, new Binding("Label") { Source = item });
50+
}
51+
52+
else if (series == series3)
53+
{
54+
item.MarkerSettings = new ChartMarkerSettings()
55+
{
56+
Fill = Colors.LightSeaGreen,
57+
Width = 15,
58+
Height = 15,
59+
Stroke = Colors.Green,
60+
StrokeWidth = 3,
61+
Type = ShapeType.Diamond
62+
};
63+
64+
dateLabel3.SetBinding(Label.TextProperty, new Binding("Date") { Source = item.DataItem, StringFormat = "{0:dd/MM/yyyy}" });
65+
valueLabel3.SetBinding(Label.TextProperty, new Binding("Label") { Source = item });
66+
}
67+
}
68+
}
69+
}
70+
71+
}
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 DisplayTrackballValues
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+
}

0 commit comments

Comments
 (0)