tradingview/lightweight-charts-android

Remove PriceLine show error

iman051996 opened this issue · 4 comments

i try to remove the PriceLine from chart,
im using code to create Price Line like this

lateinit var priceLines : PriceLines
priceLines = series.createPriceLine(
    PriceLineOptions(
        price = 54266,
        color = Color.parseColor(color_str).toIntColor(),
        lineWidth = LineWidth.TWO,
        lineStyle = LineStyle.SOLID,
        axisLabelVisible = true,
    )
)

and code to remove PriceLine is

series.removePriceLine(priceLines)

But the result is show :
java.lang.IllegalStateException: Error: PriceLine with uuid:852792bb-5c75-41a3-ae39-14e92d85b1a3 is not found

How to fix it ? Thanks

Hi! When do you use the method removePriceLine?

I guess you using this method after destroying of view. Am I right?

yea, i wanted to refresh the chart to remove the priceline
i place the remove priceline inside this script

realtimeDataJob = lifecycleScope.launchWhenResumed {
     viewModel.seriesFlow.collect{
      // inside here
     }
}

i have try to reload the view, such as re-call the activity/fragment, its worked

in other case, is it have other method to remove the priceline without re-call the activity/fragment ?

All references like priceLine are bound to WebView instance (because js heap can't be shared between instances). So if you want to remove price line, you should remove it on the same instance of ChartsView. Also if your instance of ChartsView is recreated you should release that references.
We will make some improvements in lifecycle of charts to make that cases more clear. For now you should control lifecycle of ChartsView by yourself

oke got it, thanks for advice master,
we waiting for next best improvements, and good luck