Axis min/max y value

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

feberhard
Posts: 3
Joined: Mon Nov 13, 2017 1:45 pm

Axis min/max y value

Post by feberhard » Wed Nov 22, 2017 5:04 pm

Hi,

is there a more efficient way to get the min/max y values of all axes than to perform the following steps

1. get min/max x-values per series grouped by axis by calling series.GetXMinMax(out xMin, out xMax)
2. get min/max y-value per series grouped by axis by calling series.GetMinMaxFromXRange(out yMin, out yMax, xMin, xMax, true)

I tried to use axis.GetSeriesMinMax(out min, out max) but it didn't return the right values when no data was visible in the current chart area (data is outside current visible axes values)

Following is the code I'm now using:

Code: Select all

double[] xAxisMinimums = Enumerable.Repeat(double.MaxValue, this.Chart.ViewXY.XAxes.Count).ToArray();
double[] xAxisMaximums = Enumerable.Repeat(double.MinValue, this.Chart.ViewXY.XAxes.Count).ToArray();

// Get x-axes min/max
foreach (var seriesPerAxis in this.Chart.ViewXY.PointLineSeries.GroupBy(pls => pls.AssignXAxisIndex))
{
	var xAxisIndex = seriesPerAxis.Key;
	var xAxis = this.Chart.ViewXY.XAxes[xAxisIndex];

	foreach (var series in seriesPerAxis)
	{
		double min, max;
		if (series.GetXMinMax(out min, out max))
		{
			xAxisMinimums[xAxisIndex] = Math.Min(xAxisMinimums[xAxisIndex], min);
			xAxisMaximums[xAxisIndex] = Math.Max(xAxisMaximums[xAxisIndex], max);
		}
	}
}

double[] yAxisMinimums = Enumerable.Repeat(double.MaxValue, this.Chart.ViewXY.YAxes.Count).ToArray();
double[] yAxisMaximums = Enumerable.Repeat(double.MinValue, this.Chart.ViewXY.YAxes.Count).ToArray();

// Get y-axes min/max
foreach (var seriesPerAxis in this.Chart.ViewXY.PointLineSeries.GroupBy(pls => pls.AssignYAxisIndex))
{
    var yAxisIndex = seriesPerAxis.Key;
    var yAxis = this.Chart.ViewXY.YAxes[yAxisIndex];

    foreach (var series in seriesPerAxis)
    {
        double min, max;
        if (series.GetMinMaxFromXRange(out min, out max, xAxisMinimums[series.AssignXAxisIndex], xAxisMaximums[series.AssignXAxisIndex], true))
        {
            yAxisMinimums[yAxisIndex] = Math.Min(yAxisMinimums[yAxisIndex], min);
            yAxisMaximums[yAxisIndex] = Math.Max(yAxisMaximums[yAxisIndex], max);
        }
    }
}

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

Re: Axis min/max y value

Post by ArctionKestutis » Thu Nov 23, 2017 11:20 am

Hi,

Which version of LightningChart you are using. The following code works just fine (in v8.2.1.1 for WinForms) for both approaches (axisY.GetSeriesMinMax and Series.GetMinMaxFromXRange)

Code: Select all

            AxisY axisY = _chart.ViewXY.YAxes[0];
            
            double dMin, dMax;
            axisY.GetSeriesMinMax(out dMin, out dMax);
            System.Diagnostics.Debug.WriteLine(string.Format("For all series on yAxis Min={0} and Max={1}", dMin, dMax));

            List<SeriesBaseXY> listAllSeriesOfAxisY = new List<SeriesBaseXY>(_chart.ViewXY.GetSeriesOfAxisY(axisY));

            for (int iL=0; iL < listAllSeriesOfAxisY.Count; iL++)
            {
                SeriesBaseXY sb = listAllSeriesOfAxisY[iL];

                if (sb is PointLineSeriesBase)
                {
                    PointLineSeriesBase pls = (sb as PointLineSeriesBase);
                    double xMin, xMax, yMin, yMax;
                    if (pls.GetXMinMax(out xMin, out xMax))
                    {
                        pls.GetMinMaxFromXRange(out yMin, out yMax, xMin, xMax, true);
                        System.Diagnostics.Debug.WriteLine(string.Format("Line={0}, xMin={1}, xMax={2}, yMin={3}, yMax={4}", iL, xMin, xMax, yMin, yMax));
                    }
                }
            }
I am getting same result. Tested with visible data and with panned data outside of view.

All the best.