Skip to content

Commit 04bb8f6

Browse files
Updated sample
1 parent 4591fb8 commit 04bb8f6

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed

GetDataPointsSample/AppShell.xaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:local="clr-namespace:GetDataPointsSample"
7-
Shell.FlyoutBehavior="Disabled"
7+
Shell.FlyoutBehavior="Flyout"
88
Title="GetDataPointsSample">
99

10-
<ShellContent
11-
Title="Home"
12-
ContentTemplate="{DataTemplate local:MainPage}"
13-
Route="MainPage" />
10+
<ShellContent Title="Custom Drawing"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
<ShellContent Title="Selection Zoom Event"
15+
ContentTemplate="{DataTemplate local:SelectionZoomEvent}"
16+
Route="SelectionZoomEvent" />
1417

1518
</Shell>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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:model="clr-namespace:GetDataPointsSample"
6+
x:Class="GetDataPointsSample.SelectionZoomEvent"
7+
Title="SelectionZoomEvent">
8+
9+
10+
<ContentPage.BindingContext>
11+
<model:ScatterSeriesViewModel x:Name="viewModel"/>
12+
</ContentPage.BindingContext>
13+
14+
<chart:SfCartesianChart HorizontalOptions="Fill" VerticalOptions="Fill"
15+
x:Name="cartesianChart"
16+
IsTransposed="True"
17+
SelectionZoomDelta="Chart_SelectionZoomDelta"
18+
SelectionZoomEnd="Chart_SelectionZoomEnd">
19+
20+
<chart:SfCartesianChart.ZoomPanBehavior>
21+
<chart:ChartZoomPanBehavior EnableSelectionZooming="True"/>
22+
</chart:SfCartesianChart.ZoomPanBehavior>
23+
24+
<chart:SfCartesianChart.XAxes>
25+
<chart:NumericalAxis x:Name="primaryAxis" Minimum="100" Maximum="220"
26+
Interval="20"/>
27+
</chart:SfCartesianChart.XAxes>
28+
29+
<chart:SfCartesianChart.YAxes>
30+
<chart:NumericalAxis x:Name="secondaryAxis" Minimum="50" Maximum="80" Interval="5"/>
31+
</chart:SfCartesianChart.YAxes>
32+
33+
<chart:SfCartesianChart.Series>
34+
<chart:ScatterSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue" Opacity="0.8" Fill="#FE7A36" >
35+
<chart:ScatterSeries.SelectionBehavior>
36+
<chart:DataPointSelectionBehavior Type="Multiple" SelectionBrush="#3652AD"/>
37+
</chart:ScatterSeries.SelectionBehavior>
38+
</chart:ScatterSeries>
39+
</chart:SfCartesianChart.Series>
40+
41+
</chart:SfCartesianChart>
42+
43+
</ContentPage>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Syncfusion.Maui.Charts;
2+
3+
namespace GetDataPointsSample;
4+
5+
public partial class SelectionZoomEvent : ContentPage
6+
{
7+
public SelectionZoomEvent()
8+
{
9+
InitializeComponent();
10+
}
11+
private void Chart_SelectionZoomEnd(object sender, ChartSelectionZoomEventArgs e)
12+
{
13+
primaryAxis.ZoomFactor = 1;
14+
primaryAxis.ZoomPosition = 0;
15+
secondaryAxis.ZoomFactor = 1;
16+
secondaryAxis.ZoomPosition = 0;
17+
}
18+
19+
private void Chart_SelectionZoomDelta(object sender, ChartSelectionZoomDeltaEventArgs e)
20+
{
21+
var selectedIndexes = new List<int>();
22+
23+
if (cartesianChart is SfCartesianChart)
24+
{
25+
foreach (var series in cartesianChart.Series)
26+
{
27+
if (series is ScatterSeries scatterSeries)
28+
{
29+
30+
var rect = new Rect(e.ZoomRect.X - cartesianChart.SeriesBounds.Left, e.ZoomRect.Y, e.ZoomRect.Width, e.ZoomRect.Height);
31+
var dataPoints = scatterSeries.GetDataPoints(rect);
32+
33+
if (dataPoints != null && viewModel != null)
34+
{
35+
for (int i = 0; i < viewModel.Data.Count; i++)
36+
{
37+
if (dataPoints.Contains(viewModel.Data[i]))
38+
selectedIndexes.Add(i);
39+
}
40+
scatterSeries.SelectionBehavior.SelectedIndexes = selectedIndexes;
41+
}
42+
}
43+
}
44+
}
45+
46+
}
47+
}
48+

0 commit comments

Comments
 (0)