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

ChartYAxis valueFormatter NSFormatter instead of NSNumberFormatter #228

Closed
eliotfowler opened this issue Jul 18, 2015 · 6 comments
Closed

Comments

@eliotfowler
Copy link

Once you have the data you need to place the y-axis labels on the line in order, why do you need the value formatter be a NSNumberFormatter as opposed to just a NSFormatter. The reason I ask is I'm trying to plot times and I'd like to be able to show it in MM:SS format instead of minute.fraction format.

The same could be true with the labels placed above/below the data points.

@danielgindi
Copy link
Collaborator

Y values are number, hence NSNumberFormatter, which accepts numbers. If you want to print time, then subclass NSNumberFormatter, parse the time decimal and output a string.

@mathiasgithub
Copy link

It would be great to support other formatter types because subclassing NSNumberFormatter and overriding

 func stringFromNumber(number: NSNumber) -> String? 

is a bit awkward if you're creating a new formatter type in that function to for example parse dates.

@liuxuan30
Copy link
Member

@mathiasgithub but y axis is meant to be numbers, right? I don't know if the y axis is about dates, how do you draw the charts? What's the meaning? Any examples?

@mathiasgithub
Copy link

@liuxuan30 here's one of the formatters I would love to be able to use:

    static var dateComponentsFormatter: NSDateComponentsFormatter {
        let dateComponentsFormatter = NSDateComponentsFormatter()
        dateComponentsFormatter.allowedUnits = [.Minute, .Second]
        dateComponentsFormatter.collapsesLargestUnit = true
        dateComponentsFormatter.zeroFormattingBehavior = .Pad
        return dateComponentsFormatter
    }

I use it to convert seconds (Int) to a string with the format MM:SS

I think it's useful to be able to represent the values on the y axis in any way you might want. NSNumberFormatter limits that.

NSDateComponentsFormatter inherits from NSFormatter

@liuxuan30
Copy link
Member

I see. It will calculate the y axis range to determine how we draw the chart. We cannot change it to NSFormatter, since it does not provide a default implementation for converting from double values. We could provide one, but seems it requires a decent work on it, without a high priority. If you want this support, you are more than welcome to file a PR :)

@mathiasgithub
Copy link

Thank you! No problem, I understand. I’ll see what I can do with that PR

Cheers

On 14 Dec 2015, at 11:55, Xuan [email protected] wrote:

I see. It will calculate the y axis range to determine how we draw the chart. We cannot change it to NSFormatter, since it does not provide a default implementation for converting to double values. We could provide one, but seems like it requires a decent work on it, without a high priority. If you want this support, you are more than welcome to file a PR :)


Reply to this email directly or view it on GitHub #228 (comment).

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

4 participants