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();
}
- Aditya Kadambi asked 3 years ago
- You must login to post comments
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
- Yura Khariton answered 3 years ago
- You must login to post comments
Please login first to submit.