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

0
0

Hi, I’ve been working on recyclerview with scichart.The problem i’m facing is that sometimes,when you come back from other screens the charts is not loading eventhough the other data in the list are showing.The list is placed inside a view pager .This issue is not consistant sometimes it shows the graph sometimes it won’t .The exception i’m getting are

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5260)
at android.view.ViewGroup.addView(ViewGroup.java:5089)

2021-08-17 14:50:52.639 15073-29533/com.fascilityconnex.voicemobile E/SciChart Rendering Errors: SciChartSurface has no XAxes. Please ensure SciChartSurface.XAxis is set, or SciChartSurface.XAxes has at least one axis
2021-08-17 14:50:52.641 15073-29531/com.fascilityconnex.voicemobile E/Exception: null
java.lang.UnsupportedOperationException: AxisCollection.getAxisById(‘DefaultAxisId’) returned more than one axis with the ID=DefaultAxisId. Please check you have assigned correct axis Ids when you have multiple axes in SciChart
at com.scichart.charting.model.AxisCollection.getAxisById(SourceFile:10)

Version
4.2.0.4557
Images
  • You must to post comments
0
0

Hi Vinu,

I took a look on your code and I noticed that you have method setChartData() where you have next code:

  UpdateSuspender.using(binding.surfaceChart) {
                Collections.addAll(binding.surfaceChart.xAxes, xAxis)
                Collections.addAll(binding.surfaceChart.yAxes, yAxis)
                Collections.addAll(binding.surfaceChart.renderableSeries, rSeries)
                Collections.addAll(
                    binding.surfaceChart.chartModifiers,
                    sciChartBuilder.newModifierGroupWithDefaultModifiers().build()
                )
                // sciChartBuilder.newAnimator(rSeries).withSweepTransformation().start()
               binding.surfaceChart.renderableSeriesAreaBorderStyle =
                    sciChartBuilder.newPen().withColor(ColorUtil.Transparent).build()

            }

This means that every time this method is called it adds xAxis and yAxis values into chart from binding, that are stored in ViewHolder. Also please have in mind that xAxes and yAxes are lists, so you can add same item multiple times.

Then this code is indirectly called in onBindViewHolder() method ( you call extractListData() which calls setChartData() there ). This method can be called multiple times ( every time some RecyclerView item View goes out of viewport, it is recycled and when there is new item to show onBindViewHolder() is called to set new data to display).

This leads us to the fact that if onBindViewHolder() is called more than once, you will end up with xAxes/yAxes collection which contains multiple items with same xAxis/yAxis instance. As result when chart will try to add same axis for the second time it will throw these exceptions.

To fix this you need to ensure that this doesn’t happen ( e.g. you can add axes and series into chart in constructor of ViewHolder or you can clear xAxes/yAxes collections before adding axes ). Also you can take a look on our demo application – we have several examples where we use RecyclerView ( e.g. spark lines example or EEG chanels example )

Hope this will help you!

Best regards,
Yura

  • You must to post comments
0
0

Thankyou Yura Khariton. Let me try this.

  • You must to post comments
0
0

Hi Yura Khariton, I’ve tried your solution by clearing xAxes/yAxes collections before adding axes. It works fine ,but there was a click listener on the chart surface now its not working and following error is there

Rendering Errors: SciChartSurface has no XAxes. Please ensure SciChartSurface.XAxis is set, or SciChartSurface.XAxes has at least one axis
2021-08-19 12:12:20.484 17051-11417/com.fascilityconnex.voicemobile E/SciChart Rendering Errors: SciChartSurface has no XAxes. Please ensure SciChartSurface.XAxis is set, or SciChartSurface.XAxes has at least one axis

  • Yura Khariton
    Well it looks likes that at some moment chart tries render chart, but there is no XAxis present. Probably it could be caused by clearing axes collection ( I can’t be 100% sure ). Do you clear axes collections inside UpdateSuspender.using() block? For me it is hard to tell why this happens without debugging the code. Can you provide project which reproduces this issue so I can debug it on my PC?
  • You must to post comments
0
0

//iterating the x and y axis values
fun setChartData(samples: List) {

        try {

            dataSeries.acceptsUnsortedData = true
            samples.forEachIndexed { index, data ->
                //   if(android.text.TextUtils.isDigitsOnly(data.value))
                dataSeries.append(
                    DateUtil.generateDateObjectFromDateTimeString(data.timeStamp),
                    data.value.toDouble()
                )
            }
            val rSeries = sciChartBuilder.newLineSeries().withDataSeries(dataSeries)
                .withStrokeStyle(
                    Color.parseColor(context!!.getString(R.string.graph_color)),
                    1f,
                    false
                ).build()

            binding.surfaceChart.yAxes.clear()
            binding.surfaceChart.xAxes.clear()
            binding.surfaceChart.renderableSeries.clear()

            UpdateSuspender.using(binding.surfaceChart) {
                Collections.addAll(binding.surfaceChart.xAxes, xAxis)
                Collections.addAll(binding.surfaceChart.yAxes, yAxis)
                Collections.addAll(binding.surfaceChart.renderableSeries, rSeries)
                Collections.addAll(
                    binding.surfaceChart.chartModifiers,
                    sciChartBuilder.newModifierGroupWithDefaultModifiers().build()
                )
                // sciChartBuilder.newAnimator(rSeries).withSweepTransformation().start()
               binding.surfaceChart.renderableSeriesAreaBorderStyle =
                    sciChartBuilder.newPen().withColor(ColorUtil.Transparent).build()

            }
        } catch (numberFormatException: NumberFormatException) {

        }
    }

This is how i cleared the axes collection.I’ve also cleared it inside the suspender function but the result is same

  • Yura Khariton
    Can you try to move clear() calls inside UpdateSuspender.using() block, so they won’t trigger redrawing of chart and as result this rendering error?
  • Vinu Gilbert
    Hi Yura, I ‘ve tried moving clear() calls inside UpdateSuspender.using() block.This approch works fine, but sometimes throws an exception and click listener on doesn’t work.Do i need to implement a diffrent approach than the current one. The code is provided below UpdateSuspender.using(binding.surfaceChart) { binding.surfaceChart.yAxes.clear() binding.surfaceChart.xAxes.clear() Collections.addAll(binding.surfaceChart.xAxes, xAxis) Collections.addAll(binding.surfaceChart.yAxes, yAxis) Collections.addAll(binding.surfaceChart.renderableSeries, rSeries) Collections.addAll( binding.surfaceChart.chartModifiers, sciChartBuilder.newModifierGroupWithDefaultModifiers().build() ) // sciChartBuilder.newAnimator(rSeries).withSweepTransformation().start() } }
  • Yura Khariton
    If you modify chart within listener then you also need to use UpdateSuspender.using() there to prevent trying to render chart while you modify it
  • Vinu Gilbert
    Hi, This how i added click on chart surface.The code is in onBindViewHolder() UpdateSuspender.using(holder.binding.surfaceChart){ holder.binding.surfaceChart.chartModifiers.add(CustomClickModifier(historianDataSourceModel)) } inner class CustomClickModifier(val historianDataSourceModel: List) : GestureModifierBase() { override fun onSingleTapConfirmed(e: MotionEvent?): Boolean { kpiclickListner.onListItemClicK(historianDataSourceModel) return true } } it sometimes show rendering issue while click on chart surface and lead to crash
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.