Pre loader

zoomExtents not always working

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums


I am working on CreateMultiPaneStockChartFragment example. Sometimes after I refresh data and call surface.zoomExtents(), the chart does not zoom to fit but stays the same. Why is this? I can then manually zoom to extents by double tapping the chart.

This is my (simplified) fragment code (stemming from the example but optimized for my case of regular updating) below. updateChart() is called periodically every 10 sec.

public void onCreate(@Nullable Bundle savedInstanceState) {

    sciChartBuilder = SciChartBuilder.instance();

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    surface = view.findViewById(;

private void initChart(){
    final DefaultLayoutManager layoutManager = new DefaultLayoutManager.Builder().setRightOuterAxesLayoutStrategy(new RightAlignedOuterVerticallyStackedYAxisLayoutStrategy()).build();

    final CategoryDateAxis xAxis = sciChartBuilder.newCategoryDateAxis()
        .withLabelProvider(new TradeChartAxisLabelProviderDateTime())
    xAxis.setMinimalZoomConstrain(10d); // minimum data points


    final NumericAxis yAxisPrice = sciChartBuilder.newNumericAxis()
        .withGrowBy(new DoubleRange(0.01d, 0.01d))
        .withLabelProvider(new NumericLabelProviderPrice(coinCurrency))

    // add axes for MACD, RSI, VOL..

    legendModifier = sciChartBuilder.newModifierGroup()
    // surface.getChartModifiers().add(legendModifier); // this causes crash; add it after series are present

    interactionModifiers = sciChartBuilder.newModifierGroup()

    cursorModifier = sciChartBuilder.newModifierGroup()

private void updateChart(int daysToShow) {
    final PriceSeries priceData = getData(daysToShow);


    // price chart
    final OhlcDataSeries<Date, Double> stockPrices = sciChartBuilder.newOhlcDataSeries(Date.class, Double.class).withSeriesName(getString(R.string.price)).build();
    stockPrices.append(series.getDateData(), series.getOpenData(), series.getHighData(), series.getLowData(), series.getCloseData());
    final BaseRenderableSeries seriesOHLCV = sciChartBuilder.newCandlestickSeries().withDataSeries(stockPrices).withSeriesInfoProvider(new CustomOHLCSeriesInfoProvider()).withYAxisId(PRICES).build();

    surface.getAnnotations().add(sciChartBuilder.newAxisMarkerAnnotation().withY1(stockPrices.getYValues().get(stockPrices.getCount()-1)).withBackgroundColor(Color.WHITE).withFontStyle(12, Color.BLACK).withYAxisId(PRICES).build());

    // do the same for MACD, RSI, VOL ...

        surface.getChartModifiers().add(legendModifier); // this causes crash if added before any series is present

    if(!silent) {
        Log.d("debug", "surface.zoomExtents()");
        surface.zoomExtents(); // sometimes this does not work
  • You must to post comments

Hi Primoz,

Without project which reproduce this issue it will be very hard to determine the cause of this issue because ZoomExtendsModifier uses zoomExtends() under the hood. So it’s probably some kind of race condition when you call zoomExtends() too soon when data isn’t updated yet or something like that.

Also it could be some exception so I would suggest you to check logcat output. Do you see any errors there?

Best regards,

  • Primoz
    Hi Yura! I’ve commented zoomExtentsModifier and the same still happens. Also there is no error or debug message in logcat regarding zoomExtents(). So all that happens is series and annotation is updated and zoomExtents() is called. Maybe at that time the min/max datarange is not yet calculated by SciChart internally so I should wait a few ms before calling this function? I found out the following answer (which is for WPF), but it has same issue. I didn’t find any beginInvoke function in Android though. See here:
  • Primoz
    I also tried using UpdateSuspender when replacing the series and annotation and calling zoomExtents() at the end but the issue persists because the underlying cause is still there (no min max datarange calculated yet internally?).
  • Yura Khariton
    Can you modify one of our examples from demo app or provide a project which reproduces this issue so I could debug it on my PC?
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.