Search Results for

    Show / Hide Table of Contents

    ViewportManager - Full Control over Axis Ranges and Viewport

    The ViewportManager API provides fine-grained control over the SciChartSurface viewport, allowing you to configure the result of VisibleRange calculations on a per-axis basis, change zoom level or invalidate a chart.

    You can declare a viewport manager and assign to a SciChartSurface using the following code. By default SciChart has a DefaultViewportManager assigned. You can also inherit this type and provide your own Viewport Managers.

    • Java
    • Java with Builders API
    • Kotlin
    // Assume a surface has been created and configured somewhere
    surface.setViewportManager(new DefaultViewportManager());
    
    // Assume a surface has been created and configured somewhere
    surface.setViewportManager(new DefaultViewportManager());
    
    // Assume a surface has been created and configured somewhere
    surface.viewportManager = DefaultViewportManager()
    

    Overriding Axis VisibleRanges

    The most powerful feature of the ViewportManager is the abilty to intercept the Axis VisibleRange calculations and return your own custom range. Use this if you want to have full control over the axis, not just set a new VisibleRange.

    Define your own ViewportManager as follows:

    • Java
    • Java with Builders API
    • Kotlin
    class CustomViewportManager extends DefaultViewportManager {
        @Override
        protected void onUpdateXAxis(IAxisCore xAxis) {
            super.onUpdateXAxis(xAxis);
            // called before drawing of xAxis
            // here you can update visible range
            final IRange visibleRange = xAxis.getVisibleRange();
        }
    
        @Override
        protected void onUpdateYAxis(IAxisCore yAxis) {
            super.onUpdateYAxis(yAxis);
            // called before drawing of yAxis
            // here you can update visible range
            final IRange visibleRange = yAxis.getVisibleRange();
        }
        @Override
        protected void onApplyAutoRange(IAxisCore axis) {
            super.onApplyAutoRange(axis);
            // called when axis uses AutoRange.Always or AutoRange.Once
            // here you can update visible range when need to perform auto range
            final IRange visibleRange = axis.getVisibleRange();
        }
    }
    
    class CustomViewportManager extends DefaultViewportManager {
        @Override
        protected void onUpdateXAxis(IAxisCore xAxis) {
            super.onUpdateXAxis(xAxis);
            // called before drawing of xAxis
            // here you can update visible range
            final IRange visibleRange = xAxis.getVisibleRange();
        }
    
        @Override
        protected void onUpdateYAxis(IAxisCore yAxis) {
            super.onUpdateYAxis(yAxis);
            // called before drawing of yAxis
            // here you can update visible range
            final IRange visibleRange = yAxis.getVisibleRange();
        }
        @Override
        protected void onApplyAutoRange(IAxisCore axis) {
            super.onApplyAutoRange(axis);
            // called when axis uses AutoRange.Always or AutoRange.Once
            // here you can update visible range when need to perform auto range
            final IRange visibleRange = axis.getVisibleRange();
        }
    }
    
    class CustomViewportManager : DefaultViewportManager() {
        override fun onUpdateXAxis(xAxis: IAxisCore) {
            super.onUpdateXAxis(xAxis)
            // called before drawing of xAxis
            // here you can update visible range
            val visibleRange = xAxis.visibleRange
        }
    
        override fun onUpdateYAxis(yAxis: IAxisCore) {
            super.onUpdateYAxis(yAxis)
            // called before drawing of yAxis
            // here you can update visible range
            val visibleRange = yAxis.visibleRange
        }
    
        override fun onApplyAutoRange(axis: IAxisCore) {
            super.onApplyAutoRange(axis)
            // called when axis uses AutoRange.Always or AutoRange.Once
            // here you can update visible range when need to perform auto range
            val visibleRange = axis.visibleRange
        }
    }
    

    Then attach it to a chart. If you put a breakpoint in your updateXAxis(IAxisCore xAxis) / updateYAxis(IAxisCore yAxis) methods you will see these being hit when the chart resizes or redraws and you can manipulate the calculated visible range passed to SciChart as you wish.

    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml