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

Using NSNumberFormatter or .getBarBounds() to Display Custom Values #302

Closed
trishfromtisch opened this issue Aug 14, 2015 · 1 comment
Closed

Comments

@trishfromtisch
Copy link

Hi there. I'm new to Swift, and after hours of research, I still can't find a solution to my problem. I have a bar chart where I would like to have custom values over each bar. Here's a screenshot of the look I'm trying to achieve:
screen shot 2015-08-14 at 2 10 46 pm
Unfortunately, none of the pre-existing NSNumberFormatterStyles will give me the bottom metric (abbreviated currency string), and I don't see how I can pass an individual bar's value and the sum of all values into a customNumberFormatter to get the top metric (percentage), so that I can have my formatter return a string interpolated with both metrics.

Another solution I thought to try was to access the coordinates and height of each bar and simply create and populate a UILabel over each bar, but when I try:
for entry in chartDataSet or barChartView.data or chartData {
var barRect : CGRect = barChartView.getBarBounds(entry)
...
}
I get " does not have a member named 'Generator'". I apologize if this is a noob question, but I'm honestly at my wit's end.

@trishfromtisch trishfromtisch changed the title Using NSNumberFormatter or to Display Custom Values Using NSNumberFormatter or .getBarBounds() to Display Custom Values Aug 14, 2015
@danielgindi
Copy link
Collaborator

The thing about NSNumberFormatter, is that it can do almost anything, including the "33.3%" or the "$12.4M".
And then you have the case where you just have to have it output weird values. Like "33.3%\n$12.4M". Then come in classic inheritance. Just subclass NSNumberFormatter, and make it spit out the strings that you need for the values it gets. It can include new lines...

About the "does not have a member named 'Generator'" error, it's a common compiler problem, meaning you probably passed an incorrect type. Look carefully at the type it receives and what you pass in, especially any optionals.
Also it currently returns an automatically unwrapped optional CGRect! (which will probably be changed to CGRect? in the future) - so that could also be the cause of the error.

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