Constant Line on X-axis

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

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

Constant Line on X-axis

Post by ludur » Thu Mar 05, 2020 12:01 pm

Hello,

I need Constant Line for both X and Y axis, and for Y-axis I am able to use "Arction.Wpf.SemibindableCharting.SeriesXY.CONSTANTLINE", and add it to "ConstantLineCollection" .... but, I do not know, what to use for X-axis, how to add a constant line on a X-axis :(

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

Re: Constant Line on X-axis

Post by Arction_LasseP » Fri Mar 06, 2020 7:54 am

Hello,

Currently X-axes have no ConstantLines available like Y-axes do. However, there are several ways to draw something similar for X-axis. For example a Band, LineSeriesCursor, PolygonSeries or FreeformPointLineSeries could be used.

Of these Band is by far the best option. It can be bound to X-axis to have a vertical band or to Y-axis to have a horizontal band. Disabling MouseResize but allowing MoveByMouse results to exact same behaviour as with a ConstantLine.
ValueBegin and ValueEnd determine the width of the Band (can be set simultaneously via SetValues()).

Here is an example of adding a Band:

Code: Select all

            Band band = new Band(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
            band.Binding = AxisBinding.XAxis; // Vertical Band
            band.MouseResize = false; // Cannot be resized by mouse
            band.MoveByMouse = true; // Can be moved by mouse
            band.Fill.Color = Colors.Red;
            band.Fill.GradientFill = GradientFill.Solid;
            band.SetValues(5, 6); // Set width
            band.Behind = true; // Show behind other series
            _chart.ViewXY.Bands.Add(band);
Hope this helps.
Best regards,
Lasse

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

Re: Constant Line on X-axis

Post by ludur » Fri Mar 06, 2020 8:52 am

and is there any chance to make the line of the Band to be "Dash" or "Dot" ?

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

Re: Constant Line on X-axis

Post by Arction_LasseP » Fri Mar 06, 2020 9:54 am

Hello,

That is unfortunately not possible with Bands, unless using Bitmap fills or ClipAreas to hide parts of the Band, but these would be unnecessarily complicated. Therefore if you need dashed or dotted pattern, I'd recommend using another option that is LineSeriesCursor, which in many ways is similar to a Band or a ConstantLine.

Cursors are mostly used to track series, but this feature can be disabled by setting SnapToPoints to false and CursorStyle to VerticalNotracking. After that the cursor behaves similarly to a ConstantLine.

Code: Select all

            LineSeriesCursor cursor = new LineSeriesCursor(_chart.ViewXY, axisX);
            cursor.ValueAtXAxis = 5;    // Assign cursor to X-position 5.
            cursor.SnapToPoints = false;
            cursor.Style = CursorStyle.VerticalNoTracking;
            cursor.LineStyle.Pattern = LinePattern.Dash;
            _chart.ViewXY.LineSeriesCursors.Add(cursor);
Hope this helps.
Kind regards,
Lasse