How can I get Y values using single ConstantLine

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Arction_LasseP

Junseob
Posts: 2
Joined: Fri Aug 04, 2017 2:37 am

How can I get Y values using single ConstantLine

Post by Junseob » Thu Nov 15, 2018 3:03 pm

Hello,

I have some problems when I get Y values.

My chart has few Y axes but only have 1 ConstantLine in there.
When we are creating ConstantLine, it needs to be set the owner Y axis.
Therefore it can be read only its' axis value.

I want to get every axis values using 1 ConstantLine. I don't want to make many ConstantLine for reading Y value.
Is it possible?

ArctionKestutis
Posts: 383
Joined: Mon Mar 14, 2016 9:22 am

Re: How can I get Y values using single ConstantLine

Post by ArctionKestutis » Fri Nov 16, 2018 9:18 am

Hello,

You will loose precision, but you can use converters. That is, in event handler you could use screen coordinates to/from axis values converters (Axis.ValueToCoord and Axis.CoordToValue) to estimate the position of ConstantLine. For example,

Code: Select all

            ConstantLine constantLine = chart.ViewXY.ConstantLines[0];
            // get screen coordinates [px] for Line value
            float yCoord = chart.ViewXY.YAxes[0].ValueToCoord(constantLine.Value, false);

            for (int iY = 0; iY < chart.ViewXY.YAxes.Count; iY++)
            {
                AxisY axisY = chart.ViewXY.YAxes[iY];
                // estimate Axis value for corresponding screen coordinate
                double yValue;
                axisY.CoordToValue(yCoord, out yValue, false);
                System.Diagnostics.Debug.WriteLine(string.Format("Yaxis #[{0}], Line at [{1}]", iY, yValue));
            }
Hope this helps.

MathewNi
Posts: 1
Joined: Tue Jan 08, 2019 10:00 am

Re: How can I get Y values using single ConstantLine

Post by MathewNi » Wed Jan 09, 2019 12:12 pm

Can you regain the precision that you lost by using converters after the fact somehow?