Selecting point in FreeformPointLineSeries

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Arction_LasseP

Post Reply
ludur
Posts: 5
Joined: Tue Apr 09, 2019 8:35 am

Selecting point in FreeformPointLineSeries

Post by ludur » Tue Apr 09, 2019 8:39 am

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?

Arction_LasseP
Posts: 50
Joined: Wed Mar 27, 2019 1:05 pm

Re: Selecting point in FreeformPointLineSeries

Post by Arction_LasseP » Tue Apr 09, 2019 12:16 pm

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:

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;
        }

ludur
Posts: 5
Joined: Tue Apr 09, 2019 8:35 am

Re: Selecting point in FreeformPointLineSeries

Post by ludur » Mon Sep 02, 2019 12:03 pm

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.

Arction_LasseP
Posts: 50
Joined: Wed Mar 27, 2019 1:05 pm

Re: Selecting point in FreeformPointLineSeries

Post by Arction_LasseP » Mon Sep 02, 2019 12:57 pm

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.

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;
        }
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

Post Reply