Hello,
I have FreeformPointLineSeries in semibindable-WPF with settings LineVisible="False" PointsVisible="True", an I would like to Select a Point in the chart, so that I can react on the selected point changed, and perform some action when user selects a point. Could you please help me how to do it?
Selecting point in FreeformPointLineSeries
Moderator: Queue Moderators
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Selecting point in FreeformPointLineSeries
Hello,
The best way to do this is to use mouse events and SeriesEventMarkers as done in one of our demo examples, "Value tracking with markers" (ExampleDataPointTracking). You need to set a marker for each series point and then add a mouse event, for example MouseClick, to that marker. You can then define the action inside the event.
Here is an example code:
The best way to do this is to use mouse events and SeriesEventMarkers as done in one of our demo examples, "Value tracking with markers" (ExampleDataPointTracking). You need to set a marker for each series point and then add a mouse event, for example MouseClick, to that marker. You can then define the action inside the event.
Here is an example code:
Code: Select all
SeriesPoint[] points = new SeriesPoint[pointCount];
Random rand = new Random();
for (int i = 0; i < pointCount; i++)
{
points[i].X = 50 + (rand.NextDouble() - 0.5) ;
points[i].Y = i;
}
freeformPointLineSeries.Points = points;
_chart.ViewXY.FreeformPointLineSeries.Add(freeformPointLineSeries);
//Add marker for each point, to act as an editing point
for (int i = 0; i < pointCount; i++)
{
SeriesEventMarker marker = new SeriesEventMarker(freeformPointLineSeries);
marker.XValue = points[i].X;
marker.YValue = points[i].Y;
//store values in label text
marker.Label.Text = points[i].X.ToString("0.0") + " ; " + points[i].Y.ToString("0.0");
marker.Label.Visible = false;
marker.MouseClick += new MouseEventHandler(Marker_MouseClick);
freeformPointLineSeries.SeriesEventMarkers.Add(marker);
}
private void Marker_MouseClick(object sender, MouseEventArgs e)
{
((SeriesEventMarker)sender).Label.Visible = true;
}
Re: Selecting point in FreeformPointLineSeries
Hello, thanks for the answer... and what about the "clickable" line? ... so, I have LineVisible="true" PointsVisible="false" ... and I would like that I can click on the Line, and react on it.
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Selecting point in FreeformPointLineSeries
Hello,
Clickable line is simpler to implement than clickable data point. You can just subscribe to MouseClick -event (or MouseDoubleClick) and have your code about what should happen inside the event. The event has a sender object, which can be used to identify the actual series that was clicked in case there are several FreeformPointLineSeries in the chart, and changes should affect only to the clicked series.
In the example above, when a series is clicked, its data points are shown/hidden. It doesn't matter how many series are subscribed to the same event as the point visibility is changed for only the clicked series.
Note that this same approach can be used when LineVisible=false and PointsVisible=true instead of using SeriesEventMarkers as I described in the previous post. The downside is that modifying a single data point is quite difficult this way, as the changes will affect all the data points belonging to the clicked series, not just the clicked point.
Hope this helps.
Best regards,
Lasse
Clickable line is simpler to implement than clickable data point. You can just subscribe to MouseClick -event (or MouseDoubleClick) and have your code about what should happen inside the event. The event has a sender object, which can be used to identify the actual series that was clicked in case there are several FreeformPointLineSeries in the chart, and changes should affect only to the clicked series.
Code: Select all
freeformPointLineSeries.MouseClick += FreeformPls_MouseClick; // Subscribe to the event
private void FreeformPls_MouseClick(object sender, MouseEventArgs e)
{
FreeformPointLineSeries fpls = sender as FreeformPointLineSeries;
fpls.PointsVisible = !fpls.PointsVisible;
}
Note that this same approach can be used when LineVisible=false and PointsVisible=true instead of using SeriesEventMarkers as I described in the previous post. The downside is that modifying a single data point is quite difficult this way, as the changes will affect all the data points belonging to the clicked series, not just the clicked point.
Hope this helps.
Best regards,
Lasse