12

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.

enter image description here

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
  • same issue here, but reverse, I want to show all the values of xAxis (I have 12 values but it shows only 6 of them!! ) did you find any solution for your problem ?? Commented Jan 16, 2017 at 11:59

3 Answers 3

16

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

Sign up to request clarification or add additional context in comments.

2 Comments

"needs to be set after the data has been set" is to be noted. thanks
this helped me but brought another problem. As my x axis values are TimeInterval of each day in the month, all the x axis values are same, scrolling indefinitely. how can I fix this? for example, if first x point is 10/10/16 in dd/MM/yy format all the other values also is same even after unlimited scrolling. whats wrong in this?
8

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

_chartView.xAxis.labelCount = 5;

Swift

chartView.xAxis.labelCount = 5

Comments

0

Here is my finding!!

  1. you don't need to really use label count if you are using DefaultAxisValueFormatter, NEVER use this. a lot of errors pop ! just use no2.

  2. chart.setVisibleXRangeMaximum(number) will do. please put this after chart data setting here you can see detail

    combinedChartView.data = combineData. //this need to come first
    combinedChartView.setVisibleXRangeMaximum(2) //after data setting
    

1 Comment

This is exactly what I wrote as an answer 4 years ago :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.