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

Force axis granularity #3727

Closed
bcbeta opened this issue Oct 31, 2018 · 4 comments
Closed

Force axis granularity #3727

bcbeta opened this issue Oct 31, 2018 · 4 comments

Comments

@bcbeta
Copy link

bcbeta commented Oct 31, 2018

I have a line chart that plots values every three hours. I would like the x axis to label every 24 hours so I set granularity to 8. However the values never line up appropriately I think because of the normalization code below. Is it possible to force the granularity to a certain value?

if axis.granularityEnabled { interval = interval < axis.granularity ? axis.granularity : interval } // Normalize interval let intervalMagnitude = pow(10.0, Double(Int(log10(interval)))).roundedToNextSignficant() let intervalSigDigit = Int(interval / intervalMagnitude) if intervalSigDigit > 5 { // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 // if it's 0.0 after floor(), we use the old value interval = floor(10.0 * intervalMagnitude) == 0.0 ? interval : floor(10.0 * intervalMagnitude) }

@liuxuan30
Copy link
Member

the granularity is not what you think. read the comment

    /// When true, axis labels are controlled by the `granularity` property.
    /// When false, axis values could possibly be repeated.
    /// This could happen if two adjacent axis values are rounded to same value.
    /// If using granularity this could be avoided by having fewer axis values visible.
    @objc open var granularityEnabled = false

@bcbeta
Copy link
Author

bcbeta commented Nov 1, 2018

Is there a way to set the marking interval for the x axis without hacking the granularity property? If I remove the normalization code I get the behavior I am looking for (axis labels every 8 points or 24 hours)-

img_7412

@liuxuan30
Copy link
Member

for how-to question, ask on stack overflow.

@metrue
Copy link

metrue commented Jul 31, 2021

Is it possible to hide the axis values?

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

3 participants