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



every time we update the chart, the lines jump around and it seems we need to have a delay before calling zoomExtents() for it to work properly – but even with 500ms delay, zoomExtents still does not work always (see 0:27 of below video- what helped was manually moving the chart). We want a smooth transition when changing timescale. My guess is we are misusing the library somehow, but after thorough reading through the docs we could still not fix this.

Here is a video showcasing this problem:

Here is the code that updates the surface. Basically we clear the Renderable Series of surface before we show new data. Full code where we make charts (on each update) is seen here:

// OHLC Chart Data
ohlcData.append(ohlcSeries.getDateData(), ohlcSeries.getOpenData(), ohlcSeries.getHighData(), ohlcSeries.getLowData(), ohlcSeries.getCloseData());

// Bollinger Upper Band
XyDataSeries<Date, Double> bollUpper = sciChartBuilder.newXyDataSeries(Date.class, Double.class).withSeriesName("BBU").build();
bollUpper.append(ohlcSeries.getDateData(), upperBB_data);
BaseRenderableSeries seriesBBU = sciChartBuilder.newLineSeries().withDataSeries(bollUpper).withStrokeStyle(Color.rgb(70,130,180), 1f).withYAxisId(PRICES).build();

//* ... some more lines and indicators built here ... */

// clear surface on update

// create series
seriesMA.setIsVisible(SharedPreferencesInstance.getBoolean("advanced_chart_show_ma", true));
seriesEMA.setIsVisible(SharedPreferencesInstance.getBoolean("advanced_chart_show_ema", true));
seriesBBU.setIsVisible(SharedPreferencesInstance.getBoolean("advanced_chart_show_boll", true));
seriesBBL.setIsVisible(SharedPreferencesInstance.getBoolean("advanced_chart_show_boll", true));
seriesBBM.setIsVisible(SharedPreferencesInstance.getBoolean("advanced_chart_show_boll", true));

surfaceOhlc.getRenderableSeries().add(sciChartBuilder.newCandlestickSeries().withDataSeries(ohlcData).withSeriesInfoProvider(new CustomOHLCSeriesInfoProvider()).withYAxisId(PRICES).build()); // todo : setClipToRounds(true)

  • Yura Khariton
    Hi Primoz. I’m not sure what could cause this issue based on information which you provided. Can you provide entire project or modify one of our examples to reproduce this issue so we can debug it on our side? Thanks in advance.
  • Primoz
    It is very hard for us to provide a running example as this is deeply integrated into closed sourced code. Let me ask differently – how do we properly update the charts with new data; e.g. which objects do we need to “clear” and do we need to use UpdateSuspender or not (in some examples you are using it)? Let’s say we implemented 10s update on your example here (get new data from server). How do we plug in new data to charts? Do we call surface.getRenderableSeries().clear() and then add them a new, or is this wrong? We can’t find any docs on how to properly do this.
  • You must to post comments

Hi Primoz,

To answer your question – yes it’s preferable to call code which modifies chart in UpdateSuspender block which prevents redrawing of chart while it’s used. This solves two problems:

  • performance problem because of multiple redrawing of chart. Our API built in a such way that it tries to redraw chart when you change something and if you change multiple properties this can lead to multiple invalidation of chart. WIth UpdateSuspender all invalidates within using() block will be aggregated into one redraw of chart and from chart’s perspective all changes made to chart will look like single invalidate of chart
  • race conditions. By default our chart creates a separate Thread for rendering and if you don’t use UpdateSuspender then in some rare cases you can get exceptions because of race condition when chart renderer tries to read property or collection which is currently modified from another thread. UpdateSuspender helps to prevent this because it tells chart and its renderer when you change chart so it won’t render when you change something.

BTW I would also suggest you to take a look on our Showcase demo which shows some more complex examples of using SciChart with realtime updates – Maybe it will be helpfull.

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.