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


I have a candlestick chart to display an Ohlc data. (Kotlin, Android)

        val candlestickXAxist = sciChartBuilder

        val candlestickYAxist = sciChartBuilder

        val fastCandlestickRenderableSeries = sciChartBuilder.newCandlestickSeries()

        UpdateSuspender.using(priceChart) {
            Collections.addAll(priceChart.xAxes, candlestickXAxist)
            Collections.addAll(priceChart.yAxes, candlestickYAxist)
            Collections.addAll(priceChart.annotations, this.currentAnnotation)
            Collections.addAll(priceChart.renderableSeries, this.fastCandlestickRenderableSeries)
            Collections.addAll(priceChart.chartModifiers, sciChartBuilder.newModifierGroupWithDefaultModifiers().build())

In some cases, I need the chart displays the data in a specific date (X value) instead of user should move/pan the chart.

I have tried this

                val lastData = priceSeries.last()
                val lastTime = lastData.timePeriodStart.time
                val oneHourAgo = lastTime - 1000*60*60

                Log.i("CHAR_DEMO", "Display time from ${Date(oneHourAgo)} to ${Date(lastTime)}")

                candlestickXAxist.visibleRange = DoubleRange(lastTime.toDouble(), oneHourAgo.toDouble())

But it didn’t work.

And notice that, I’m not sure why the chart xAxis is CategoryDateAxis but the visibleRange is IRange instead of DateRange.

enter image description here

Can someone help me?

Thank you.

  • You must to post comments

Hi Vo Hoa,

Thanks for your inquiry.

As I see you’re using CategoryDateAxis and it is index based ( expects DoubleRange with indices to display ). This axis type allows to insert same Date more than once and as result you can’t define VisibleRange with Dates because axis won’t know which Date to use in this case. So that’s why setting of DateRange won’t work and that’s why setting DoubleRange with double representation of Date won’t work either.

To fix your code you need to set DoubleRange which contains the index of oneHourAgo and lastTime Dates ( please note that Min should be less than Max ):

candlestickXAxist.visibleRange = DoubleRange(priceSeries.indexOf(oneHourAgo), priceSeries.indexOf(lastTime))

Hope this will help you!

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.