LiveCharts2
LiveCharts2 copied to clipboard
ChartPointPointerDown event issue with scatter series
Describe the bug
I want to determine which point a user clicked on a scatter series. In some cases, the event will fire twice for both points sharing the same X axis value. The points are not close to each other on the Y axis (Visually there is a degree of separation between the points).
For example, I have an event to turn the point purple in this demo. Clicking either the star or circle turns both points purple. This occurs for the 1st, 2nd and 4th pairs.
To Reproduce ViewModel for demo:
public partial class ViewModel
{
public ViewModel()
{
var series1 = new ScatterSeries<MyMetrics, SVGPathGeometry>
{
Values = new ObservableCollection<MyMetrics>()
{
new() {Date=DateTime.Parse("2024-07-31 14:00"),Value = 1.5},
new() {Date=DateTime.Parse("2024-07-31 15:00"),Value = 1.6},
new() {Date=DateTime.Parse("2024-07-31 16:00"),Value = 1.7},
new() {Date=DateTime.Parse("2024-07-31 17:00"),Value = 1.8},
new() {Date=DateTime.Parse("2024-07-31 18:00"),Value = 1.9}
},
GeometrySvg = SVGPoints.Circle,
Mapping = (metric, value) => new(metric.Date.Ticks, metric.Value)
};
var series2 = new ScatterSeries<MyMetrics, SVGPathGeometry>
{
Values = new ObservableCollection<MyMetrics>()
{
new() {Date=DateTime.Parse("2024-07-31 14:00"),Value = 1.1},
new() {Date=DateTime.Parse("2024-07-31 15:00"),Value = 2.0},
new() {Date=DateTime.Parse("2024-07-31 16:00"),Value = 1.0},
new() {Date=DateTime.Parse("2024-07-31 17:00"),Value = 2.0},
new() {Date=DateTime.Parse("2024-07-31 18:00"),Value = 1.1},
},
GeometrySvg = SVGPoints.Star,
Mapping = (metric, value) => new(metric.Date.Ticks, metric.Value)
};
series1.ChartPointPointerDown += OnPointerDown;
series2.ChartPointPointerDown += OnPointerDown;
Series = new ISeries[] { series1, series2 };
}
private void OnPointerDown(LiveChartsCore.Kernel.Sketches.IChartView chart, LiveChartsCore.Kernel.ChartPoint<MyMetrics, LiveChartsCore.SkiaSharpView.Drawing.Geometries.SVGPathGeometry, LiveChartsCore.SkiaSharpView.Drawing.Geometries.LabelGeometry>? point)
{
if (point?.Visual is null) return;
point.Visual.Fill = new SolidColorPaint(SKColors.BlueViolet);
}
public ISeries[] Series { get; set; }
}
public class MyMetrics
{
public DateTime Date { get; set; }
public double Value { get; set; }
}
Expected behavior Ideally, the event would fire once matching on the point closest point. Also, the event shouldn't fire unless the click is in very close proximity to the point.
Desktop (please complete the following information): Windows 11. WinForms app.
PS Great work on this project. Thank you. ♥️