Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two series into one chart and scale one of them #146

Open
armanTabib opened this issue Jun 23, 2024 · 1 comment
Open

Add two series into one chart and scale one of them #146

armanTabib opened this issue Jun 23, 2024 · 1 comment

Comments

@armanTabib
Copy link

I'm using lightweight-chart-android on my compose application and I'm hosting an area view and a volume at the bottom (exactly like this). But the problem is that I want to scale the volume, so I do these:

api.addAreaSeries(options = AreaSeriesOptions(
                                lastValueVisible = false,
                                visible = true,
                                topColor  = ContextCompat.getColor(context, R.color.asset_details_area_top_color).toIntColor(),
                                bottomColor = ContextCompat.getColor(context, R.color.asset_details_area_bottom_color).toIntColor(),
                                lineColor = ContextCompat.getColor(context, R.color.asset_details_area_line_end_color).toIntColor(),
                                lineStyle = LineStyle.SOLID,
                                lineWidth = LineWidth.ONE,
                                lineType = LineType.SIMPLE,
                                priceFormat = PriceFormat(type = PriceFormat.Type.PRICE),
                            ), onSeriesCreated = {areaAPI ->
                                areaAPI.setData(chartState.chartData.map {data ->
                                    data.toHistogramPriceData()
                                })
                                areaAPI.priceScale().applyOptions{
                                    scaleMargins = PriceScaleMargins(
                                        top = 0.09f,
                                        bottom = 0.9f
                                    )
                                }
                            })



api.addHistogramSeries(options = HistogramSeriesOptions(priceFormat = PriceFormat(
                                type = PriceFormat.Type.VOLUME
                            ), color = "#BAC2C8FF".toIntColor(),),
                                onSeriesCreated = {volumeAPI ->
                                    volumeAPI.setData(chartState.chartData.map {data ->
                                        data.toHistogramVolumeData()
                                    })
                                    volumeAPI.priceScale().applyOptions {
                                        scaleMargins = PriceScaleMargins(
                                            top = 0.9f,
                                            bottom = 0f
                                        )
                                    }
                                })

If I want to explain this code, I add an areaSeries and scale it from 0.9 to 0.09 and I add a volume and scale it from 0 to 0.9 so it loads at the bottom of the page. But what I get is an scaled area view at the bottom of page overlapped with volume view.

@armanTabib
Copy link
Author

It seems that I've resolved the issue, I just added priceScaleId = PriceScaleId("2") and priceScaleId = PriceScaleId("1") to seriesOptions when adding series, though I'm not sure how it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant