Page 1 of 1

LineSeriesCursor and Z

Posted: Tue Nov 23, 2021 2:30 pm
by Niels Decker
Is it possible to assign an individual Z order to LineSeriesCursors, so that they run behind one graph but above another? I could only find the "behind" property that positions the LineSeriesCursor at the very front or at the very back.

Regards
Niels

Re: LineSeriesCursor and Z

Posted: Wed Nov 24, 2021 8:44 am
by Arction_LasseP
Hello Niels,

This is currently not possible. As you already found out, LineSeriesCursor can be behind all series or in front of all series.

There is a workaround that could be used in some cases. You could set the cursor color to transparent and then add an additional line series to act as a cursor. Since line series such as PointLineSeries are rendered in the order they are in the respective series list, you can have the extra series on top of some series and behind some other series. You would still need to have the LineSeriesCursor as you cannot drag a line series. Here is a small example:

Code: Select all

LineSeriesCursor cursor = new LineSeriesCursor(_chart.ViewXY, axisX);
cursor.LineStyle.Color = Color.FromArgb(0, 255, 0, 0);  // Set transparent color. Visible = false would prevent dragging.
cursor.ValueAtXAxis = 5;
cursor.SnapToPoints = false;
cursor.PositionChanged += Cursor_PositionChanged;
_chart.ViewXY.LineSeriesCursors.Add(cursor);

PointLineSeries cursorSeries = new PointLineSeries(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
cursorSeries.AllowUserInteraction = false;
cursorSeries.PointsVisible = false;
cursorSeries.LineVisible = true;
cursorSeries.CursorTrackEnabled = false; // Don't let the cursor track this series
cursorSeries.LineStyle.Color = Color.Red;
SeriesPoint[] p = new SeriesPoint[2]
{
    new SeriesPoint(5, 0),
    new SeriesPoint(5, 100)
};
cursorSeries.Points = p;
cursorSeries.Title.Text = "Cursor";
_chart.ViewXY.PointLineSeries.Insert(2, cursorSeries);


        private void Cursor_PositionChanged(object sender, PositionChangedEventArgs e)
        {
            foreach (var series in _chart.ViewXY.PointLineSeries)
            {
                if (series.Title.Text == "Cursor") // Move the cursor series when LineSeriesCursor moves
                {
                    series.Points[0].X = e.NewValue;
                    series.Points[1].X = e.NewValue;
                    series.InvalidateData();
                }
            }
        }
In the above, if there were 4 series you want to track, the cursor appears on top of the first two series but behind the last two.

As mentioned this approach can be used in some cases. There are other workarounds such as using multiple axes, but this one is perhaps the easiest one to implement.

Best regards,
Lasse