Tooltip when hovering over Point

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

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

Tooltip when hovering over Point

Post by ludur » Tue Sep 24, 2019 7:14 am

Hello,

I have a FreeformPointLineSeries, with Points, and settins LineVisible="false", PointsVisible="true" ... and I would like to display some tooltip with custom information, when hovering over a Point inside a Chart ... is that possible? :)

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

Re: Tooltip when hovering over Point

Post by Arction_LasseP » Tue Sep 24, 2019 8:53 am

Hello,

Yes, this is very possible to do. We actually have a demo example or two which does something similar to this ("Scatter, point tracking" and "Value tracking with markers"). You could check those and their source code as they can be helpful in this case.

Basically, you can have an SeriesEventMarker on top of each data point and use MouseOverOn- and MouseOverOff- events to enable and disable their visibility. The label text of a marker can be updated to show custom information about the data point. This approach works well unless there are thousands (or even tens of thousands) of data points, in which case having that many SeriesEventMarkers can start to decrease the performance of the application.

It it also possible to use only one marker and update its position by solving the nearest data point inside the MouseOverOn -event. For example:

Code: Select all

// Defining the marker
SeriesEventMarker marker = new SeriesEventMarker();
marker.MouseInteraction = false;
marker.HorizontalPosition = SeriesEventMarkerHorizontalPosition.SnapToPoints;
marker.VerticalPosition = SeriesEventMarkerVerticalPosition.AtYValue;
marker.Visible = false;
marker.Label.Border.Style = BorderType.Outer;
marker.Label.Border.Color1 = Colors.Red;
marker.Label.Distance = 15;
freeformPointLineSeries.SeriesEventMarkers.Add(marker);

freeformPointLineSeries.MouseOverOn += freeformPointLineSeries_MouseOverOn;
freeformPointLineSeries.MouseOverOff += freeformPointLineSeries_MouseOverOff;


private void freeformPointLineSeries_MouseOverOff(object sender, MouseEventArgs e)
        {
            _chart.ViewXY.FreeformPointLineSeries[0].SeriesEventMarkers[0].Visible = false;
        }

private void freeformPointLineSeries_MouseOverOn(object sender, MouseEventArgs e)
        {
            _chart.BeginUpdate();           

            double xpos, ypos;
            int index;
            if (_chart.ViewXY.FreeformPointLineSeries[0].SolveNearestDataPointByCoord((int)e.GetPosition(_chart).X, (int)e.GetPosition(_chart).Y, out xpos, out ypos, out index))
            {
                _chart.ViewXY.FreeformPointLineSeries[0].SeriesEventMarkers[0].XValue = xpos;
                _chart.ViewXY.FreeformPointLineSeries[0].SeriesEventMarkers[0].YValue = ypos;

                _chart.ViewXY.FreeformPointLineSeries[0].SeriesEventMarkers[0].Visible = true;
                _chart.ViewXY.FreeformPointLineSeries[0].SeriesEventMarkers[0].Label.Text = "X: " + xpos.ToString("0.00") + "\nY: " + ypos.ToString("0.00");
            }

            _chart.EndUpdate();
        }
Note that you can also use an Annotation instead of SeriesEventMarker's label to show the custom information. Annotations have more styling options that labels.

Hope this is helpful.
Best regards,
Lasse

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

Re: Tooltip when hovering over Point

Post by ludur » Wed Oct 09, 2019 6:37 am

Hello,

cool, it works :) Now I have just one small problem ---> it is possible to Move the Marker with Mouse, is there some way to disable this?

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

Re: Tooltip when hovering over Point

Post by Arction_LasseP » Wed Oct 09, 2019 7:22 am

Hello,

Yes, this is possible. There are two options you can choose from:

Code: Select all

marker.MouseInteraction = false;
This prevents all mouse interaction with the marker including moving it, mouse over highlighting and mouse events.

Code: Select all

marker.MoveByMouse = false;
This only prevents moving the marker with mouse but retains the other mouse interactions mentioned above.

Hope this helps.
Best regards,
Lasse