Page 1 of 1

Tooltip for series

PostPosted: Fri May 17, 2019 2:07 pm
by giryhepai
Hi,

I'm trying to display some kind of tooltip for series: when the user hovers a series -> display the name of the series (close to mouse cursor would be nice) .

Some context:
- I use multiple(up to 12000) FreeformPointLineSeries, each of them have 50 points (X: 1..50)
- I tried to accomplish this by using SeriesEventMarker but because there are so few points there are cases where the distance between the mouse cursor and the marker's label is quite big


Is there a way to set such a tooltip without relying on SeriesEventMarker?

Thanks in advance!

Re: Tooltip for series

PostPosted: Mon May 20, 2019 9:25 am
by Arction_LasseP
Hi,

Yes, this is possible without SeriesEventMarkers. One way to do this is to use an annotation and MouseOverOn and MouseOverOff - events. You can use these events to check if the mouse cursor is over a series and set annotation visibility true or false accordingly. Here is an example.

Setting the series and the annotations:

Code: Select all
FreeformPointLineSeries fpls = new FreeformPointLineSeries(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
fpls.Title.Text = "Series Name";
fpls.MouseOverOn += Fpls_MouseOverOn;
fpls.MouseOverOff += Fpls_MouseOverOff;
_chart.ViewXY.FreeformPointLineSeries.Add(fpls);

AnnotationXY ann = new AnnotationXY(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
ann.Visible = false;
ann.Style = AnnotationStyle.Rectangle;
ann.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates;
ann.MouseInteraction = false;
_chart.ViewXY.Annotations.Add(ann);


There is no need to set more than one annotation even if there are thousands of series. You can just update the location and the text of the one annotation.

The events can be as follows:

Code: Select all
private void Fpls_MouseOverOff(object sender, MouseEventArgs e)
        {
            _chart.ViewXY.Annotations[0].Visible = false;
        }

private void Fpls_MouseOverOn(object sender, MouseEventArgs e)
        {
            FreeformPointLineSeries fp = sender as FreeformPointLineSeries;
            _chart.ViewXY.Annotations[0].LocationScreenCoords.SetValues((float)e.GetPosition(_chart).X + 50, (float)e.GetPosition(_chart).Y - 40); // e.GetPosition gets the mouse position inside several mouse events.
            _chart.ViewXY.Annotations[0].Text = fp.Title.Text;
            _chart.ViewXY.Annotations[0].Visible = true;
        }


Hope this is helpful.

Re: Tooltip for series

PostPosted: Mon May 20, 2019 12:47 pm
by giryhepai
That was exactly what I was looking for.

Thanks a lot!