Pre loader

LIVE Graph, data accumulation

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

We are adding 24 channel data Live graph using Scichart Example of Vital sign monitor. We are using VitalSignsMonitorShowcaseFragment.java example.

To show the live graph, do we need to accumulate the data for 50 point or so. I see in the code they are accumulating?

Is it necessary for the accumulation, please let us know

protected void initExample(ExampleVitalSignsMonitorFragmentBinding binding) {
    final DefaultVitalSignsDataProvider dataProvider = new DefaultVitalSignsDataProvider(getActivity());

    setUpChart(dataProvider);

    dataProvider.getData().buffer(50, TimeUnit.MILLISECONDS).doOnNext(ecgData -> {
        if(ecgData.isEmpty()) return;

        dataBatch.updateData(ecgData);

        UpdateSuspender.using(binding.surface, () -> {
            final DoubleValues xValues = dataBatch.xValues;

            ecgDataSeries.append(xValues, dataBatch.ecgHeartRateValuesA);
            ecgSweepDataSeries.append(xValues, dataBatch.ecgHeartRateValuesB);

            bloodPressureDataSeries.append(xValues, dataBatch.bloodPressureValuesA);
            bloodPressureSweepDataSeries.append(xValues, dataBatch.bloodPressureValuesB);

            bloodOxygenationDataSeries.append(xValues, dataBatch.bloodOxygenationA);
            bloodOxygenationSweepDataSeries.append(xValues, dataBatch.bloodOxygenationB);

            bloodVolumeDataSeries.append(xValues, dataBatch.bloodVolumeValuesA);
            bloodVolumeSweepDataSeries.append(xValues, dataBatch.bloodVolumeValuesB);

            final VitalSignsData lastVitalSignsData = dataBatch.lastVitalSignsData;
            final double xValue = lastVitalSignsData.xValue;

            lastEcgSweepDataSeries.append(xValue, lastVitalSignsData.ecgHeartRate);
            lastBloodPressureDataSeries.append(xValue, lastVitalSignsData.bloodPressure);
            lastBloodOxygenationSweepDataSeries.append(xValue, lastVitalSignsData.bloodOxygenation);
            lastBloodVolumeDataSeries.append(xValue, lastVitalSignsData.bloodVolume);
        });
    }).compose(bindToLifecycle()).subscribe();

    updateIndicators(0);
    Observable.interval(0, 1, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
            .doOnNext(this::updateIndicators)
            .compose(bindToLifecycle()).subscribe();
}
Version
V4
  • You must to post comments
0
0

Hi Aditya,

It’s preferable, but isn’t necessary. We do append in batches because of performance reasons.

Our data provider emits new point every millisecond, so if we append data every time it’s emitted, then this would cause 1000 attempts to redraw chart per second( every time you change data series it automatically triggers redrawing of chart ). So to reduce stress on chart’s renderer we aggregate points in batches and append them every 50ms ( this is equal to 20 redraws of chart per second ).

Also we’re using batches to prevent unnecessary boxing/unboxing when appending primitive data types ( double, float, int etc ). If you take a look, for example, on XyDataSeries append overloads you will see that overload which accepts single data point has generic params(TX x, TY y), so if you append, for example, 2 primitive double values, then they will be boxed to 2 Double objects, and then under the hood they will be unboxed back to 2 primitive doubles. In simple cases this shouldn’t be a problem, but in realtime apps where append method is called multiple times it can lead to performance problems because of creating many objects, which then should be collected by Android GC. To avoid this overhead we use append overload which accepts IValues instances.

Hope this will help you!

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