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.
// Assume a surface has been created and configured somewhere
surface.setViewportManager(new 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:
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();
}
}
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.