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

improvement: custom labels on BarChart #1095

Closed
ADevelopStudio opened this issue May 31, 2016 · 8 comments
Closed

improvement: custom labels on BarChart #1095

ADevelopStudio opened this issue May 31, 2016 · 8 comments
Labels

Comments

@ADevelopStudio
Copy link

ADevelopStudio commented May 31, 2016

if in file HorizontalBarChartRenderer.swift (line 310) change :
let valueText = formatter.stringFromNumber(val)!
to:

 var valueText = formatter.stringFromNumber(val)!     
 if let labelValue = e.data as? String {
        valueText = labelValue
 }

and add this label to

 BarChartDataEntry(value: values[i], xIndex: i, data: "YOUR_CUSTOM_LABEL_AS_STRING")

it will add custom labels to chart
simulator screen shot 31 may 2016 21 56 49

@ADevelopStudio ADevelopStudio changed the title custom labels on BarChart improvement: custom labels on BarChart May 31, 2016
@liuxuan30
Copy link
Member

It's a little obscure to figure out the difference, what you want to achieve? I guess value formatter can take care of the prefix and appendix

@ADevelopStudio
Copy link
Author

this graph displays daily value of some vitamins, as an example.
so bar represents percentage but labels on the right shows exact amount.
because not app vitamins (in my case) has the same daily value. I mean some of them can be 1g and some 0.01g. As you can see on the chart, Vitamin K has only 154 mcg ( 0.154mg) but daily percentage is much bigger than Vitamin E with 2mg.
You can't do it with value formatter, first of all because prefix and appendix are common for all values. you can't use different for each bar. Plus here I display the exact amount as label and daily percentage as bar at the same time

@liuxuan30
Copy link
Member

I see. For now, I would suggest you do some customizations to meet your goal.
@danielgindi seems more and more people are asking about custom value labels

@ADevelopStudio
Copy link
Author

no worries, I reached my goal by doing this way. I just wanted to share my suggestion

@hardikdevios
Copy link

+1

@danielgindi
Copy link
Collaborator

Yes, and there are many open issues...
I need some help here managing the issues, marking duplicates/bugs/feature requests etc.
I have more work now taking care of a new baby girl :-)

@liuxuan30
Copy link
Member

I am trying to as much as possible to label them. BTW, congrats

@danielgindi
Copy link
Collaborator

Implemented in Charts 3.0 (v3 branch)

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

No branches or pull requests

4 participants