Search code examples
iosswiftchartsios-charts

Charts for iOS: limit displayed entries number to 4 in LineChartView


I'm using LineChartView to draw line charts in our application. The newest requirement is that the chart displays only 4 records at once, so the X-zoom must be limited to 4 entries. Is this achievable using this library without doing any hacky stuff? I'd rather avoid calculating zoom manually.

Thanks in advance!


Solution

  • If I understand correctly, you want to see only 4 values at a time. This can be accomplished by using:

    chartView.setVisibleXRange(minXRange: 4.0, maxXRange: 4.0)
    

    The chart will be scrollable to the sides. The scroll can be turned off, but then only the 4 first values will be viewable:

    chartView.isUserInteractionEnabled = false