1

I'm using SciChart on my android application to display a Candlestick chart. When the y-values are big, the chart displays the data well.

When the y-values is big, the chart display well.

But when the y-values are small, the chart doesn't display well. It has the default scale level. You can see the values (red/green dots) at the bottom, very close the line y=0

enter image description here

Even when I tried to increase zoom level, seems it has a limitation of zoom level.

enter image description here

Anyone can give me some idea to fix this.

Bellow is my current implementation

private fun getOhlcDataSeries(symbolValues: List<SymbolValue>):
        OhlcDataSeries<Date, Double> {
    val dataSeries = OhlcDataSeries(Date::class.java, Double::class.javaObjectType)

    val dates = symbolValues.map { it.timePeriodStart }
    val opens = symbolValues.map { it.priceOpen }
    val high = symbolValues.map { it.priceHigh }
    val lows = symbolValues.map { it.priceLow }
    val closes = symbolValues.map { it.priceClose }

    dataSeries.append(dates, opens, high, lows, closes)
    return dataSeries
}

val sciChartBuilder = SciChartBuilder.instance()
    val priceSeries = getData()

    val xAxis = sciChartBuilder.newCategoryDateAxis().build()
    val yAxis = sciChartBuilder.newNumericAxis().build()

    val dataSeries = getOhlcDataSeries(priceSeries)

    val upColor = 0xFF64AA6F.toInt()
    val downColor = 0xFFE25C5A.toInt()

    val rSeries = sciChartBuilder.newCandlestickSeries()
            .withStrokeUp(upColor)
            .withFillUpColor(upColor)

            .withStrokeDown(downColor)
            .withFillDownColor(downColor)

            .withDataSeries(dataSeries)
            .build()

    UpdateSuspender.using(surface) {
        Collections.addAll(surface.xAxes, xAxis)
        Collections.addAll(surface.yAxes, yAxis)
        Collections.addAll(surface.renderableSeries, rSeries)
        Collections.addAll(surface.chartModifiers, sciChartBuilder.newModifierGroupWithDefaultModifiers().build())
    }

Thank you

Võ Quang Hòa
  • 2,688
  • 3
  • 27
  • 31

2 Answers2

2

I tried many solutions and finally, it works by adding this

    yAxis.minimalZoomConstrain = 0.00000001
    yAxis.maximumZoomConstrain = 1000000
Võ Quang Hòa
  • 2,688
  • 3
  • 27
  • 31
0

Have you tried to use AutoRange.Always for your yAxis?

val yAxis = sciChartBuilder.newNumericAxis().withAutoRangeMode(AutoRange.Always).build()

It should force yAxis to apply autorange to fit the data on screen every time the chart is drawn.

Disclosure: I am the lead developer on the SciChart Android team

Yura Khariton
  • 484
  • 2
  • 6
  • 1
    Thanks for your reply. It doesn't work but this one work. yAxis.minimalZoomConstrain = 0.00000001 yAxis.maximumZoomConstrain = 1000000 I think base on this issue, you can improve a little bit the library so other people will not face this issue again. – Võ Quang Hòa Mar 03 '18 at 17:15