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

Get current axis interval between labels #2281

Closed
acegreen opened this issue Mar 25, 2017 · 5 comments
Closed

Get current axis interval between labels #2281

acegreen opened this issue Mar 25, 2017 · 5 comments

Comments

@acegreen
Copy link

acegreen commented Mar 25, 2017

In my case I'm setting both granularity and labelcount, with the intention of having an even grid, 20x20 grids (labels) and a certain minimum granularity. This seems to work but I can display the current interval.

Doing leftAxis.granularity would display the minimum I set and not the current axis interval. Is there any way to get that or do I have to do some computation like getting two values on that axis and subtracting them?

    leftAxis.granularityEnabled = true
    leftAxis.granularity = granularityY
    leftAxis.forceLabelsEnabled = true
    leftAxis.labelCount = labelCount
@acegreen acegreen changed the title Get current axis interval Get current axis interval between labels Mar 25, 2017
@liuxuan30
Copy link
Member

liuxuan30 commented Mar 27, 2017

    open func setLabelCount(_ count: Int, force: Bool)
    {
        self.labelCount = count
        forceLabelsEnabled = force
    }

use this to set labelCount.

    open var labelCount: Int
    {
        get
        {
            return _labelCount
        }
        set
        {
            _labelCount = newValue
            
            if _labelCount > 25
            {
                _labelCount = 25
            }
            if _labelCount < 2
            {
                _labelCount = 2
            }
            
            forceLabelsEnabled = false
        }
    }

The setter is different.

@acegreen
Copy link
Author

@liuxuan30 thats not the point though. I wanted to find a way to get the current interval (granularity) of my chart. As mentioned, the granularity I set is in my case not respected and thats fine since I want to force the labels but I would like to add the real granularity to my charts legend

@liuxuan30
Copy link
Member

sorry I missed. No idea what's the convenient way to get interval. But one trick is to get two neighbor x values and use the ChartTransformer to calculate the interval in screen pixels.

@acegreen
Copy link
Author

Thanks for the reply. So I got two neighbouring values. What property of ChartTransformer could I use? On a side note, shouldn't the _granularity property be updated to reflect the "real" granularity as opposed to granularity which we define as the minimum?

@liuxuan30
Copy link
Member

liuxuan30 commented Mar 29, 2017

I don't fully understand about granularity yet, but I do know granularity is used to be designed to filter repeated axis labels. so I am just thinking about getting intervals.
ChartTransformer has something like pointValuesToPixel and pixelsToValues to do convert.

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