IOS-Charts set maximum visible x axis values

佐手、 提交于 2019-12-04 00:29:29

问题


I'm using ios-charts (https://github.com/danielgindi/Charts). I have a LineChartView with 12 values in the x axis. This however is far too many to see at the same time, so I want to display only 5 and then let the user drag to the right to see the next.

I've tried this:

    let chart = LineChartView()
    chart.dragEnabled = true
    chart.setVisibleXRangeMaximum(5)

    let xAxis = chart.xAxis
    xAxis.axisMinValue = 0
    xAxis.axisMaxValue = 5.0
    xAxis.setLabelsToSkip(0)

But still see all 11 values at the time. How can I only see 5?


回答1:


I finally got it!

The correct answer is:

chart.setVisibleXRangeMaximum(5)

This however needs to be set after the data has been set in the chart (not in a configure before)

This did the trick for me




回答2:


You should set the X axis's labelCount property of the chart view. In objc,like this

_chartView.xAxis.labelCount = 5;


来源:https://stackoverflow.com/questions/39576113/ios-charts-set-maximum-visible-x-axis-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!