-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SyncfusionExamples/876723-How-to-highlight…
…-selected-data-points-by-using-GetDataPoints-method-in-.NET-MAUI-Cartesian-Charts MAUI-876723 How to highlight selected data points by using get data points method in .net ma UI cartesian charts
- Loading branch information
Showing
4 changed files
with
209 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts" | ||
xmlns:model="clr-namespace:GetDataPointsSample" | ||
x:Class="GetDataPointsSample.SelectionZoomEvent" | ||
Title="SelectionZoomEvent"> | ||
|
||
|
||
<ContentPage.BindingContext> | ||
<model:ScatterSeriesViewModel x:Name="viewModel"/> | ||
</ContentPage.BindingContext> | ||
|
||
<chart:SfCartesianChart HorizontalOptions="Fill" VerticalOptions="Fill" | ||
x:Name="cartesianChart" | ||
SelectionZoomDelta="Chart_SelectionZoomDelta" | ||
SelectionZoomEnd="Chart_SelectionZoomEnd"> | ||
|
||
<chart:SfCartesianChart.ZoomPanBehavior> | ||
<chart:ChartZoomPanBehavior EnableSelectionZooming="True"/> | ||
</chart:SfCartesianChart.ZoomPanBehavior> | ||
|
||
<chart:SfCartesianChart.XAxes> | ||
<chart:NumericalAxis x:Name="primaryAxis" Minimum="100" Maximum="220" | ||
Interval="20"/> | ||
</chart:SfCartesianChart.XAxes> | ||
|
||
<chart:SfCartesianChart.YAxes> | ||
<chart:NumericalAxis x:Name="secondaryAxis" Minimum="50" Maximum="80" Interval="5"/> | ||
</chart:SfCartesianChart.YAxes> | ||
|
||
<chart:SfCartesianChart.Series> | ||
<chart:ScatterSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue" | ||
Opacity="0.8" Fill="#FE7A36" | ||
PointWidth="8" | ||
PointHeight="8"> | ||
<chart:ScatterSeries.SelectionBehavior> | ||
<chart:DataPointSelectionBehavior Type="Multiple" SelectionBrush="#3652AD"/> | ||
</chart:ScatterSeries.SelectionBehavior> | ||
</chart:ScatterSeries> | ||
</chart:SfCartesianChart.Series> | ||
|
||
</chart:SfCartesianChart> | ||
|
||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Syncfusion.Maui.Charts; | ||
|
||
namespace GetDataPointsSample; | ||
|
||
public partial class SelectionZoomEvent : ContentPage | ||
{ | ||
public SelectionZoomEvent() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void Chart_SelectionZoomDelta(object sender, ChartSelectionZoomDeltaEventArgs e) | ||
{ | ||
var selectedIndexes = new List<int>(); | ||
|
||
foreach (var series in cartesianChart.Series) | ||
{ | ||
if (series is ScatterSeries scatterSeries) | ||
{ | ||
var rect = new Rect(e.ZoomRect.X - cartesianChart.SeriesBounds.Left, e.ZoomRect.Y, e.ZoomRect.Width, e.ZoomRect.Height); | ||
var dataPoints = scatterSeries.GetDataPoints(rect); | ||
|
||
if (dataPoints != null && viewModel != null) | ||
{ | ||
for (int i = 0; i < viewModel.Data.Count; i++) | ||
{ | ||
if (dataPoints.Contains(viewModel.Data[i])) | ||
selectedIndexes.Add(i); | ||
} | ||
scatterSeries.SelectionBehavior.SelectedIndexes = selectedIndexes; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void Chart_SelectionZoomEnd(object sender, ChartSelectionZoomEventArgs e) | ||
{ | ||
primaryAxis.ZoomFactor = 1; | ||
primaryAxis.ZoomPosition = 0; | ||
secondaryAxis.ZoomFactor = 1; | ||
secondaryAxis.ZoomPosition = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters