How can i calculator average

Not familiar with licensing? Need help in installing LightningChart Ultimate SDK? User's manual is missing? Post general questions here.

Moderator: Arction_LasseP

Post Reply
Lawrence_Jung
Posts: 14
Joined: Mon Jul 03, 2017 8:43 am

How can i calculator average

Post by Lawrence_Jung » Mon Jul 03, 2017 8:57 am

hello.
my English is not perfect. sorry.....

I need some help. because i try calculator average from between cursor to cursor for winform charts
X axis is time stamp and Y axis is random value.

1. i'm using "GetMinMaxFromXRange". but it need start and end range. how can i know range?
2. how can i calculator average??

thanks

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

Re: How can i calculator average

Post by ArctionKestutis » Mon Jul 03, 2017 10:14 am

Hello,

If you need averaged x-axis value between two cursors, the following will do it:

Code: Select all

            LineSeriesCursor cur1 = _chartSpec.ViewXY.LineSeriesCursors[0];
            LineSeriesCursor cur2 = _chartSpec.ViewXY.LineSeriesCursors[1];

            var avgTime = _chart.ViewXY.XAxes[0].AxisValueToDateTime((cur1.ValueAtXAxis + cur2.ValueAtXAxis) * 0.5);
That is, check Cursor's property ValueAtXAxis, make average and convert to DataTime if needed.

If you need conversion from Value to DataTime you would need to use following method:

Code: Select all

_chart.ViewXY.XAxes[0].DateTimeToAxisValue(dtime)
Hope this helps.

If you need some other average, please fill-in more details.

All the best.

Lawrence_Jung
Posts: 14
Joined: Mon Jul 03, 2017 8:43 am

Re: How can i calculator average

Post by Lawrence_Jung » Tue Jul 04, 2017 12:18 am

thanks for your reply. :)

i will try that!!

But i think This function is X axis only.
My charts have 1 X axis and many Y axis. and X axis is time, Y axis value.

I want Y axes average from two vertical cursor.

Lawrence_Jung
Posts: 14
Joined: Mon Jul 03, 2017 8:43 am

Re: How can i calculator average

Post by Lawrence_Jung » Tue Jul 04, 2017 12:36 am

IF X axis is value than this code is Ok
but my X axis is time....

Code: Select all

foreach (PointLineSeries series in _ChartZB.ViewXY.PointLineSeries)
            {
                double average_series = 0.0d;
                double LY, RY;
                double left_cursor, right_cursor;

                //Find positions to cursor of Left and Right 
                if (_ChartZB.ViewXY.LineSeriesCursors[1].ValueAtXAxis > _ChartZB.ViewXY.LineSeriesCursors[0].ValueAtXAxis)
                {
                    left_cursor = _ChartZB.ViewXY.LineSeriesCursors[0].ValueAtXAxis;
                    right_cursor = _ChartZB.ViewXY.LineSeriesCursors[1].ValueAtXAxis;
                    _ChartZB.ViewXY.XAxes[0].AxisValueToDateTime((_ChartZB.ViewXY.LineSeriesCursors[0].ValueAtXAxis + _ChartZB.ViewXY.LineSeriesCursors[1].ValueAtXAxis) * 0.5);
                }
                else if (_ChartZB.ViewXY.LineSeriesCursors[1].ValueAtXAxis < _ChartZB.ViewXY.LineSeriesCursors[0].ValueAtXAxis)
                {
                    left_cursor = _ChartZB.ViewXY.LineSeriesCursors[1].ValueAtXAxis;
                    right_cursor = _ChartZB.ViewXY.LineSeriesCursors[0].ValueAtXAxis;
                }
                else
                {
                    Console.WriteLine("Cursor position error!!");
                    return;
                }

                //Get Y value and check result
                if (!SolveValueAccurate(series, left_cursor, out LY))
                    LY = 0.0d;
                if (!SolveValueAccurate(series, right_cursor, out RY))
                    RY = 0.0d;
                _ChartZB.ViewXY.LineSeriesCursors[0].ThinHairCross = true;

                average_series = series.GetYValues()
                    .Skip((int)left_cursor)
                    .Take((int)(right_cursor - left_cursor + 1))
                    .Average();

                //Find Min & Max values
                if (!series.GetMinMaxFromXRange(out min, out max, left_cursor, right_cursor, false))
                {
                    Console.WriteLine("Get Min & Max Fail");
                    return;
                }

                //double[] _series = FilterRoutines.MovingAverage(series.GetYValues(), _chart.ViewXY.GetMarginsRect().Width);
                //string[] _rowString = {_seriesIndex.ToString(), min.ToString(), max.ToString(), _series[0].ToString()};
                string[] _rowString = { _seriesIndex.ToString(),                        //Axis Num
                                          LY.ToString(),
                                          RY.ToString(),
                                          min.ToString(),                               //Minimum Value
                                          max.ToString(),                               //Maximum Value
                                          average_series.ToString() };   //Value of average
                gridData.Add(_rowString);
                _seriesIndex++;
            }

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

Re: How can i calculator average

Post by ArctionKestutis » Tue Jul 04, 2017 8:05 am

Hello,

It should be now difference whatever your xAxis Time, Date or MapCoordinates. Internally all types converted to Value, some unified form.

I guess your SolveValueAccurate() method is borrowed from Demo App example and is using Series.SolveYValueAtXValue(Value) method.

The most direct call is

Code: Select all

LineSeriesValueSolveResult result = Series.SolveYValueAtXValue(cursor.ValueAtXAxis);
and it return all necessary result. If (result.SolveStatus == LineSeriesSolveStatus.OK), when you get
-> yValue = (result.YMax + result.YMin) / 2.0; // yValue at cursor's position
-> result.NearestDataPointIndex // index at PointLineSeries, where cursor stands next to

With this result you could either make average between two cursors values, or make average of Points between IndexLeft to IndexRight.

I just tested this approach on WinForms example (PointLineSeries, time on XAxis etc) and everything works fine.
If you still have problem, please send your app for testing to Arction's support account or upload to forum.

P.S. GetMinMaxFromXRange() method return just Min and Max of Y-values found in the particular X-range. I don't think it is suitable for averaged value estimate.

All the best.

Lawrence_Jung
Posts: 14
Joined: Mon Jul 03, 2017 8:43 am

Re: How can i calculator average

Post by Lawrence_Jung » Tue Jul 04, 2017 8:36 am

Thanks for your answer

I will try your answer!!

And GetMinMaxFromXrange() method use for min, max value

I need min value, max value, average value, and Now position Yvalues.

All the best.

Lawrence_Jung
Posts: 14
Joined: Mon Jul 03, 2017 8:43 am

Re: How can i calculator average

Post by Lawrence_Jung » Tue Jul 04, 2017 9:18 am

I can calculator average for your help!

and one more ask solution.

I need zoom in from some count of points.

example...I have 10000 points than i watch 100 point only in viewXY by zoom

because 1000 points is so many point.

All the best

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

Re: How can i calculator average

Post by ArctionKestutis » Tue Jul 04, 2017 9:42 am

All zooming operation uses Axis.SetRange() method. You just need to find Min & Max values of those 100 points you want to zoom-in.
Then you know desired Min&Max just call Axis.SetRange().

All the best.

Post Reply