SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on where you can earn rep for your questions!


I’m using in my geometryCursormodifier the function
var xCalc=this.XAxis.GetCurrentCoordinateCalculator();

This works under normal circumstances(Application Mode).

Now I was trying to test this features with Unit Test and xCalc is always null(this.XAxis isn’t null)?

  • You must to post comments

Hi Daniel,

The GetCurrentCoordinateCalculator() method returns a calculator only after the first render pass has occurred. It is possible to unit test it, but requires some setup. Here is an example test we have that tests Axis GetCurrentCoordinateCalculator.

    public void ShouldGetCoordinateAsXAxisAndReturnPixel()
        var calculatorFactoryStub = MockRepository.GenerateStub<ICoordinateCalculatorFactory>();
        calculatorFactoryStub.Stub(x => x.New(Arg<AxisParams>.Is.Anything))
            .Do((Func<AxisParams, ICoordinateCalculator<double>>)(x =>
                x.Offset = 0;
                return new CoordinateCalculatorFactory().New(x);

        // Mocks IServiceContainer, passed to AxisBase, required for OnBeginRenderPass to run
        _serviceContainer = new MockServiceContainerBuilder()

        var renderSurface = new MockRenderSurfaceBuilder().WithSize(new Size(400, 300)).Build();
        _axis.VisibleRange = new DoubleRange(0, 10);

        // Mocks ISciChartSurface
        _axis.ParentSurface = new MockSciChartSurfaceBuilder().WithRenderSurface(renderSurface).WithServiceContainer(_serviceContainer).Build();
        _axis.Orientation = Orientation.Horizontal;
        _axis.TextFormatting = "0.00";

        _axis.Width = 400;
        _axis.Height = 300;


        var cc = _axis.GetCurrentCoordinateCalculator();
        Assert.That(cc, Is.Not.Null);

        double coord = _axis.GetCoordinate(5.0125313283208017d);
        Assert.That(coord, Is.EqualTo(200));

Here is the definition of AxisBase.OnBeginRenderPass()

    /// <summary>
    /// Called internally immediately before a render pass begins
    /// </summary>
    public virtual void OnBeginRenderPass()
        if (Services == null)

        _currentCoordinateCalculator = Services.GetService<ICoordinateCalculatorFactory>().New(GetAxisParams());

        _currentInteractivityHelper = new AxisInteractivityHelper(_currentCoordinateCalculator);

As you can see it requires Services to be not null, and for ICoordinateCalculatorFactor to be registered. Then it can create a new coordinate calculator.

Let me know if you are able to make progress with this. It might be difficult without the source-code (since you need to look inside our code to see why test setup is / is not working).

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.