-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
Lightweight Charts™ Version: 4.0.0
Add my code
val timeScaleApi = remember { mutableStateOf<TimeScaleApi?>(null) }
val candleSeries = remember { mutableStateOf<SeriesApi?>(null) }
LaunchedEffect(candleSeries, currentGraphData, isGraphInitialized) {
val data = getCandleGraphData(currentGraphData ?: OhlcvGraphData())
timeScaleApi.value?.applyOptions {
barSpacing = 9f
}
delay(150)
if (candleSeries.value != null /*&& (currentGraphData?.ohlcvData?.size ?: 0) > 5*/) {
candleSeries.value?.setData(data)
}
}
LaunchedEffect(timeScaleApi, visibleRange) {
if (candleSeries.value != null
&& visibleRange?.to != null
&& visibleRange?.from != null
&& currentScrollableGraph != GraphType.PRICE
) {
//timeScaleApi.value?.setVisibleRange(visibleRange)
}
}
Box(modifier = modifier) {
CandleGraphGridContainer(pricesGraphPriceTags)
AndroidView(modifier = Modifier
.fillMaxHeight()
.fillMaxWidth()
.padding(
end = HasherMaterialTheme.dimensions.market_data_price_mark_width,
top = HasherMaterialTheme.dimensions.space_12,
bottom = HasherMaterialTheme.dimensions.size_6
)
.pointerInteropFilter { motionEvent ->
if (motionEvent.action == MotionEvent.ACTION_DOWN) {
changeScrollGraph(GraphType.PRICE)
}
false
},
factory = { context ->
ChartsView(context).apply {
api.applyOptions {
layout = layoutOptions {
background = SolidColor(Color.Transparent.toArgb())
textColor = IntColor(graphTextColor.toArgb())
}
grid = gridOptions {
vertLines = gridLineOptions { visible = false }
horzLines = gridLineOptions { visible = false }
}
timeScale = timeScaleOptions {
visible = false
borderVisible = false
fixLeftEdge = true
fixRightEdge = true
}
crosshair = crosshairOptions {
vertLine = crosshairLineOptions {
visible = false
labelVisible = false
}
horzLine = crosshairLineOptions {
visible = false
labelVisible = false
}
}
api.subscribeClick {
setSelectedPrice((it.time?.date?.time ?: 0L) / 1000)
}
api.timeScale.subscribeVisibleTimeRangeChange { range ->
onVisibleRangeChanged(range, GraphType.PRICE)
}
}
}
},
update = { view ->
if (timeScaleApi.value == null) {
timeScaleApi.value = view.api.timeScale
}
if (candleSeries.value == null) {
view.api.addCandlestickSeries(
options = CandlestickSeriesOptions(
lastValueVisible = false,
priceLineVisible = false,
upColor = upColor,
downColor = downColor
)
) { newSeries ->
candleSeries.value = newSeries
view.api.applyOptions {
rightPriceScale = priceScaleOptions {
mode = PriceScaleMode.NORMAL
visible = false
autoScale = true
borderVisible = false
scaleMargins = priceScaleMargins {
top = 0.001f
bottom = 0.001f
}
}
}
}
}
}
)
Stack trace:

Expected behavior:
When changing time tabs, I set new data in my Series and add a listener to change the range and synchronize the graphs. When adding a small amount of data, the graph crashes. I tried removing the subscription and there was no crash, the graph automatically updated its dimensions.
Metadata
Metadata
Assignees
Labels
No labels