Pre loader

How to properly update chart

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

0
0

Hi,

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:

https://screencast-o-matic.com/watch/cqiUjxOkV6

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();
seriesBBU.setClipToBounds(true);

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

// clear surface on update
if(!surfaceOhlc.getRenderableSeries().isEmpty())
    surfaceOhlc.getRenderableSeries().clear(); 

// 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)
surfaceOhlc.getRenderableSeries().add(seriesBBU);
surfaceOhlc.getRenderableSeries().add(seriesBBL);
surfaceOhlc.getRenderableSeries().add(seriesBBM);
surfaceOhlc.getRenderableSeries().add(seriesEMA);
surfaceOhlc.getRenderableSeries().add(seriesMA);

surfaceOhlc.getAnnotations().add(annPrice);
Version
2.5.0.2540
  • 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)? https://github.com/ABTSoftware/SciChart.Android.Examples/blob/master/v2.x/Examples/app/src/main/java/com/scichart/examples/fragments/CreateMultiPaneStockChartsFragment.java 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
0
0

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 – https://github.com/ABTSoftware/SciChart.Android.Examples/tree/master/v2.x/Showcase. Maybe it will be helpfull.

Best regards,
Yura

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies