Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last label on xAxis is not showing #1497

Closed
saxxi opened this issue Sep 20, 2016 · 2 comments
Closed

Last label on xAxis is not showing #1497

saxxi opened this issue Sep 20, 2016 · 2 comments

Comments

@saxxi
Copy link

saxxi commented Sep 20, 2016

Hi, I'm also not able to show the last label on the xAxis.

Example:

  • I have 50 data points
  • I'd like to to show the first [0], a mid point [24] and the last [49] labels

Here's a set of different attempts:

  • view.xAxis.setLabelsToSkip(25)
  • view.xAxis.setLabelsToSkip(24)
  • view.xAxis.axisLabelModulus = 24

(I'm using avoidFirstLastClippingEnabled which is fitting only the first label)

I followed Stackoverflow, a similar issue on previous version and apparently the Android version have the something along the lines.

Thank you!

@saxxi saxxi changed the title avoidFirstLastClippingEnabled Still clipping last value Last label on xAxis is not showing Sep 20, 2016
@saxxi
Copy link
Author

saxxi commented Sep 20, 2016

As v3.0 is still not in cocoapods and I cannot find the exact reference in the newer code but I think the issue is around the following place:

// in Charts/Core/ChartXAxisRenderer.swift
open func drawLabels(context: CGContext, pos: CGFloat, anchor: CGPoint) {
  ...
  for i in stride(from: self.minX, to: min(self.maxX + 1, xAxis.values.count), by: xAxis.axisLabelModulus)
    ...
  }
}

Basically this would simplify to the following:

for i in stride(from: 0, to: 50, by: 25)

Which would convert to following [0, 25] array missing therefore the last element ([50]).

I'm using: pod 'Charts', :git => 'https://github.com/danielgindi/Charts.git', :branch => 'Swift-3.0'

@liuxuan30
Copy link
Member

First you should try Chart 3.0, it has redesigned x axis rendering. Chart 2.2.5 will not have bug fix anymore.
For your question, you call stride(from: 0, to: 50, by: 25) where last value will be 0 + 25; It's your step issue. If you want to sure a middle value, I guess you have to override this method. Also You need to consider when you zooming, how do you display the middle value as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants