Skip to content

Update for WPF KB GitHub readme - KB 14773 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,86 @@

The [WPF Chart](https://www.syncfusion.com/wpf-controls/charts) allows you to select multiple scatter data points using the canvas and mouse drag.

Here are the steps to follow:

**Step 1:** Create a scatter chart within a grid layout using this documentation

**Step 2:** Initialize the canvas with mouse interaction events.

**Step 3:** Implement the mouse interaction events to select the desired data points using the mouse drag.

**C#**

```csharp
public partial class MainWindow : Window
{
#region Fields

private Point startPoint;
private Rectangle? currentRectangle;
private Rect currentRect;

#endregion

#region Constructor

public MainWindow()
{
InitializeComponent();
}

#endregion

#region Methods

private void OnMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && currentRectangle != null)
{
// Update the size of the rectangle as the mouse is dragged.
double width = e.GetPosition(drawingCanvas).X - startPoint.X;
double height = e.GetPosition(drawingCanvas).Y - startPoint.Y;
if (width > 0 && height > 0)
{
currentRect = new Rect(startPoint.X, startPoint.Y, width, height);
currentRectangle.Width = width;
currentRectangle.Height = height;
}
}
}

private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(drawingCanvas);

// Create a new rectangle.
currentRectangle = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 1,
Fill = Brushes.Transparent
};

// Add the rectangle to the canvas.
drawingCanvas.Children.Add(currentRectangle);

// Set the initial position of the rectangle.
Canvas.SetLeft(currentRectangle, startPoint.X);
Canvas.SetTop(currentRectangle, startPoint.Y);
}

private void OnMouseUp(object sender, MouseButtonEventArgs e)
{
viewModel.SelectedDataPoints = series.GetDataPoints(currentRect);
currentRectangle = null;
currentRect = Rect.Empty;
drawingCanvas.Children.Clear();
}

#endregion
}
```

The following demo visualizes how to select multiple scatter data points using mouse drag, which shows the respective values in a list view.
![Demo](https://github.com/SyncfusionExamples/How-to-Select-Multiple-Scatter-Data-Points-with-Mouse-Drag/assets/103025761/971fd74f-f660-45e3-813f-aeaf41fda735)

Expand Down