Pre loader

Line Series not persisting which switching between activities.

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

enter image description hereHi,

I have 3 separate line series and 1 column bar series. Whenever I switch between activities, Column bar data and range persist but not for the line series.

Whenever I return back from activityB to ActivityA it never calls restoreInstanceState. How can I persist the states of these graph?

Snap short attached for reference.

—–code,

initChartUI() {

    SciChartBuilder.init(mContext)
    sciChartBuilder = SciChartBuilder.instance()

    xyIapDataSeries =
            sciChartBuilder.newXyDataSeries(Date::class.javaObjectType, Short::class.javaObjectType)
                .withSeriesName(getString(R.string.label_iap)).build()

    xyTempDataSeries =
            sciChartBuilder.newXyDataSeries(Date::class.javaObjectType, Short::class.javaObjectType)
                .withSeriesName(getString(R.string.label_temperature)).build()

    xyUoDataSeries =
            sciChartBuilder.newXyDataSeries(Date::class.javaObjectType, Short::class.javaObjectType)
                .withSeriesName(getString(R.string.label_uo)).build()

    xyRrDataSeries =
            sciChartBuilder.newXyDataSeries(Date::class.javaObjectType, Short::class.javaObjectType)
                .withSeriesName(getString(R.string.label_respiratory_rate)).build()

    initChartIap(iap_chart)
    initChartUo(uo_chart)
    initChartTemp(temperature_chart)
    initChartRR(resp_rate_chart)

}

private fun initChartIap(surface: SciChartSurface) {
val xAxis = sciChartBuilder.newCategoryDateAxis()
.withBarTimeFrame(SECONDS_IN_FIVE_MINUTES.toDouble())
.withDrawMinorGridLines(false)
.withGrowBy(0.0, 0.5)
.build()
val yAxis = sciChartBuilder.newNumericAxis().withAutoRangeMode(AutoRange.Always).build()

    val line = sciChartBuilder.newLineSeries().withStrokeStyle(R.color.accuryn_blue, STROKE_THICKNESS)
        .withDataSeries(xyIapDataSeries).build()

    // Create a Stroke Pen and assign it
    val strokePen = SolidPenStyle(resources.getColor(R.color.accuryn_blue, null), true, 2f, null)
    line.strokeStyle = strokePen

    UpdateSuspender.using(surface) {
        Collections.addAll(surface.xAxes, xAxis)
        Collections.addAll(surface.yAxes, yAxis)
        Collections.addAll<BaseRenderableSeries>(surface.renderableSeries, line)
        Collections.addAll<AxisMarkerAnnotation>(surface.annotations, iapAxisMarker)
        Collections.addAll(
            surface.chartModifiers, sciChartBuilder.newModifierGroup()
                .withXAxisDragModifier().build()
                .withZoomPanModifier().withReceiveHandledEvents(true).withXyDirection(Direction2D.XDirection).build()
                .withPinchZoomModifier().build()
                .build()
        )
    }

……
rest 3 other types….
…..
override fun onSaveInstanceState(outState: Bundle) {

    outState.run {
        putInt("count", xyIapDataSeries.count)
        putInt("uoCount", xyUoDataSeries.count)
        putInt("tempCount", xyTempDataSeries.count)
        putInt("rrCount", xyRrDataSeries.count)

        val iapRange = iap_chart.xAxes[0].visibleRange
        val uoRange = uo_chart.xAxes[0].visibleRange
        val tempRange = temperature_chart.xAxes[0].visibleRange
        val rrRange = resp_rate_chart.xAxes[0].visibleRange

        putDouble("rangeIapMin", iapRange.getMinAsDouble())
        putDouble("rangeIapMax", iapRange.getMaxAsDouble())
        putDouble("rangeUoMin", uoRange.getMinAsDouble())
        putDouble("rangeUoMax", uoRange.getMaxAsDouble())
        putDouble("rangeTempMin", tempRange.getMinAsDouble())
        putDouble("rangeTempMax", tempRange.getMaxAsDouble())
        putDouble("rangeRrMin", rrRange.getMinAsDouble())
        putDouble("rangeRrMax", rrRange.getMaxAsDouble())
    }
    super.onSaveInstanceState(outState)
}

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)

    updateIapData(savedInstanceState)
    updateUoData(savedInstanceState)
    updateTempData(savedInstanceState)
    updateRRData(savedInstanceState)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
    super.onRestoreInstanceState(savedInstanceState)
     updateIapData(savedInstanceState)
    updateUoData(savedInstanceState)
    updateTempData(savedInstanceState)
    updateRRData(savedInstanceState)
}

private fun updateIapData(savedInstanceState: Bundle?) {
UpdateSuspender.using(iap_chart) {
var count = DEFAULT_POINT_COUNT
if (savedInstanceState != null) {
count = savedInstanceState.getInt(“count”)

            val rangeMin = savedInstanceState.getDouble("rangeIapMin")
            val rangeMax = savedInstanceState.getDouble("rangeIapMax")

            iap_chart.xAxes[0].visibleRange.setMinMaxDouble(rangeMin, rangeMax)
        }

        val iap = mutableListOf<Short>()
        val date = mutableListOf<Date>()
        for (entry in mSimplifiedDataList) {
            if (entry.emr.iap > 0) {
                iap.add(entry.emr.iap)
                date.add(Date(DateTimeUtils.toEpochMilli(entry.getRtcTimeStamp())))
            } else {
                iap.add(0)
                date.add(Date(DateTimeUtils.toEpochMilli(entry.getRtcTimeStamp())))
            }
        }
        tv_iap_input_data.text = iap[iap.size.minus(1)].toString()
        xyIapDataSeries.append(date, iap)
    }
}

……rest other for updating data over UI.

Version
7.1.1
  • You must to post comments
0
0

Hi Praween,

Thanks for your question.

Unfortunately I don’t think that problem with not called onRestoreInstanceState() method is related to SciChart library because it’s part of Android functionality so I don’t think that this is correct place to ask why it isn’t called. In our examples we override onActivityCreated() method and restore state there.

Regarding second part of your question about how to save state of graph – well it depends on your requirements and architecture of your application. You can serialize chart state into Bundle or some file, you can extract state of chart into ViewModel if you use MVVM and recreate View from data from ViewModel which isn’t destroyed when you close Activity or you can save state in some other way which will be more suitable for your needs.

Hope this will help you!

Best regards,
Yura

  • Praween Kumar
    To answer this question, there was bug in the 2.2.0.x jar where openGL not able to render data from persisted value. Please use 2.2.2.2424 and onwards version to avoid this problem.
  • 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