Pre loader

KeyNotFoundException in ISciList.GetMaximum()


Hi, I’m overriding FastBubbleRenderableeSeries.InternalDraw. I recently upgraded to SciChart 4 and now some of my code throws a KeyNotFoundException.

The following code, inside InternalDraw(..), results in a KeyNotFoundException.

The contents of ZPoints at the time are 0.01, 0.01.

   var points = (XyzPointSeries)renderPassData.PointSeries;

                if (points.Count == 0)

                var maxZ = (double)points.ZPoints.GetMaximum();    <---- exception thrown

Am I doing something wrong? How can I get the maximum Z value?


  • You must to post comments

Hi Felix,

I was able to reproduce this in a simple unit test:

    public void WhenGetMaximumShouldNotThrowKeyNotFoundException()
        var xyzDataSeries = new XyzDataSeries<double>();
        xyzDataSeries.Append(0, 1, 2);
        xyzDataSeries.Append(3, 4, 5);

        var xyzPointSeries = xyzDataSeries.ToPointSeries(ResamplingMode.Auto, new IndexRange(0,1), 400, false, null, new PointResamplerFactory()) as XyzPointSeries;

        Assert.That(xyzPointSeries, Is.Not.Null);
        Assert.That(xyzPointSeries.Count, Is.EqualTo(2));

        Assert.DoesNotThrow(() => xyzPointSeries.ZPoints.GetMaximum());

However, inspecting the code, we’re actually returning ISciList from the ZPoints property, and GetMaximum expects a concrete type (e.g. double, int, float). In other words ‘we didn’t expect you to call this API at this point’.

A very simple subsititution to get the maximum is to call this function instead:

// using System.Linq

Let me know if that helps.

Best regards,

  • You must to post comments

Hi Andrew,

Thanks for your reply.

Indeed this works, but I’m concerned about the performance. Presumably the LINQ Max is linear w.r.t. the number of items in the list. My charts need to be able to scale to a large number of points, and this method gets called on each redraw.

I thought your custom GetMaximum() would do some clever stuff to make it constant time.

For now I will go with your solution, but I’d appreciate a linear time way to get the max/min of points within the IRenderPassData (that works 😛 )

FYI what I’m trying to achieve here is to scale the bubbles in the bubble chart based on four factors – the viewport size, the max Z-val in view, the min Z-val in view, and the number of bubbles in view. Maybe you know of a better way to approach this than overriding InternalDraw and using renderPassData.PointSeries.ZPoints.GetMaximum() etc.?


  • Andrew Burnett-Thompson
    SciList.GetMaximum() simply iterates over all members (in a for-loop) and returns the maximum found. It does this in a fast, generic way using unsafe code. It’s as simple as that really. It is faster than .Max() but it is still linear depending on number of points I’m afraid.
  • F W
    Ah ok. I guess Max is fine then. Cheers Felix
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies