Skip to content

Commit 27ec109

Browse files
Updated
1 parent 501c10d commit 27ec109

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ This method involves handling selection zoom events to draw a custom rectangle a
129129
Initialize the [SelectionZoomDelta](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_SelectionZoomDelta) and [SelectionZoomEnd](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_SelectionZoomEnd) events in the [SfCartesianChart.](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html) Initialize the [ZoomPanBehavior](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_ZoomPanBehavior) and enable selection zoom using the [EnableSelectionZooming](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartZoomPanBehavior.html#Syncfusion_Maui_Charts_ChartZoomPanBehavior_EnableSelectionZooming) API available in [ChartZoomPanBehavior.](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartZoomPanBehavior.html)
130130

131131
```html
132-
<chart:SfCartesianChart
132+
<chart:SfCartesianChart x:Name="cartesianChart"
133133
SelectionZoomDelta="Chart_SelectionZoomDelta"
134-
SelectionZoomEnd="Chart_SelectionZoomEnd">
134+
SelectionZoomEnd="Chart_SelectionZoomEnd">
135135

136136
<chart:SfCartesianChart.ZoomPanBehavior>
137137
<chart:ChartZoomPanBehavior EnableSelectionZooming="True" />
@@ -163,33 +163,29 @@ Initialize the [SelectionZoomDelta](https://help.syncfusion.com/cr/maui/Syncfus
163163
The [SelectionZoomDelta](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_SelectionZoomDelta) event is activated during the process of selecting a region in the chart area. Inside the event handler, retrieve the selecting area rectangle values. Then, use the [GetDataPoints](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.CartesianSeries.html#Syncfusion_Maui_Charts_CartesianSeries_GetDataPoints_Microsoft_Maui_Graphics_Rect_) method to retrieve the data points that fall inside the rectangle. Update the indexes of these data points in the [SelectedIndexes](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSelectionBehavior.html#Syncfusion_Maui_Charts_ChartSelectionBehavior_SelectedIndex) property of [ChartSelectionBehavior.](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSelectionBehavior.html)
164164

165165
```csharp
166-
private void Chart_SelectionZoomDelta(object sender, ChartSelectionZoomDeltaEventArgs e)
166+
private void Chart_SelectionZoomDelta(object sender, ChartSelectionZoomDeltaEventArgs e)
167167
{
168168
var selectedIndexes = new List<int>();
169169

170-
if (cartesianChart is SfCartesianChart)
170+
foreach (var series in cartesianChart.Series)
171171
{
172-
foreach (var series in cartesianChart.Series)
172+
if (series is ScatterSeries scatterSeries)
173173
{
174-
if (series is ScatterSeries scatterSeries)
175-
{
176-
var rect = new Rect(e.ZoomRect.X - cartesianChart.SeriesBounds.Left, e.ZoomRect.Y, e.ZoomRect.Width, e.ZoomRect.Height);
177-
var dataPoints = scatterSeries.GetDataPoints(rect);
174+
var rect = new Rect(e.ZoomRect.X - cartesianChart.SeriesBounds.Left, e.ZoomRect.Y, e.ZoomRect.Width, e.ZoomRect.Height);
175+
var dataPoints = scatterSeries.GetDataPoints(rect);
178176

179-
if (dataPoints != null && viewModel != null)
177+
if (dataPoints != null && viewModel != null)
178+
{
179+
for (int i = 0; i < viewModel.Data.Count; i++)
180180
{
181-
for (int i = 0; i < viewModel.Data.Count; i++)
182-
{
183-
if (dataPoints.Contains(viewModel.Data[i]))
184-
selectedIndexes.Add(i);
185-
}
186-
scatterSeries.SelectionBehavior.SelectedIndexes = selectedIndexes;
181+
if (dataPoints.Contains(viewModel.Data[i]))
182+
selectedIndexes.Add(i);
187183
}
184+
scatterSeries.SelectionBehavior.SelectedIndexes = selectedIndexes;
188185
}
189186
}
190187
}
191-
192-
}
188+
}
193189
```
194190
**Step 3: Cancel the zoom**
195191
The [SelectionZoomEnd](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_ZoomEnd) event is invoked when selecting a region from the chart area. Inside the event handler, set the [ZoomFactor](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_ZoomFactor) to 1 and the [ZoomPosition](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_ZoomPosition) to 0. This helps cancel the zoom.

0 commit comments

Comments
 (0)