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

Value labels are not always showing in horizontal bar chart #3981

Closed
melkon90 opened this issue May 1, 2019 · 4 comments
Closed

Value labels are not always showing in horizontal bar chart #3981

melkon90 opened this issue May 1, 2019 · 4 comments

Comments

@melkon90
Copy link

melkon90 commented May 1, 2019

What did you do?

I'm using a horizontal bar chart to show some data. In my case, I've created an array with key value pairs. I've set the setDrawValues to true so that I can see the value labels next to the bar.

What did you expect to happen?

I expect to see the value labels next to the bars

What happened instead?

Depending on the values I provide, sometimes I can see the labels and other times I can't. For example:
This input shows the value labels (the difference is the value in the first key value pair):
let test: [(key: String, value: Double)] = [(key: "123", value: 10), (key: "456", value: 152), (key: "333", value: 153), (key: "890", value: 20)]

This input does not show the value labels:
let test: [(key: String, value: Double)] = [(key: "123", value: 30), (key: "456", value: 152), (key: "333", value: 153), (key: "890", value: 20)]

The difference is (what I have found till now is) that the array that works I get a false in this if statement within the HorizontalBarChartRenderer and a true in the other case:
if !viewPortHandler.isInBoundsX(rect.origin.x)
{
continue
}

Charts Environment

Charts version/Branch/Commit Number: 3.3.0
Xcode version: 10.2.1 (10E1001)
Swift version: 4.2/5
Platform(s) running Charts: iOS 11.2/12.2
macOS version running Xcode:

Demo Project

https://github.com/melkon90/Charts-ValueLabelsNotAlwaysShowing

Images

Screenshot 2019-05-01 at 12 01 09

Screenshot 2019-05-01 at 12 01 33

@melkon90
Copy link
Author

melkon90 commented May 1, 2019

I don't know why, but the value labels are shown when I change the pod version to 3.2.2. But it only works in the sample project that I've provided here, but not in my own project. Perhaps this info might help you find the issue..

@liuxuan30
Copy link
Member

liuxuan30 commented May 13, 2019

Are you sue you are using 3.3? We had #3906 merged in 3.3.0, which is a bug fix to it. But I tested on my side with ChartsDemo, it's fine.

if !viewPortHandler.isInBoundsX(rect.origin.x)

this hasn't been changed for long time. And when you say you get a false, it's really false means it's out of bound. I cannot say it's wrong.

if you want to get the text anyway, you should shutdown clipValuesToContentEnabled

        if clipValuesToContentEnabled
        {
            context.saveGState()
            context.clip(to: _viewPortHandler.contentRect)
            
            renderer.drawValues(context: context)
            
            context.restoreGState()
        }

@MelkonYoussif
Copy link

Yes I'm sure. See the demo project that I've uploaded. Currently, I've solved this problem by adding
leftAxis.axisMinimum = 0

@waveChand
Copy link

Yes I'm sure. See the demo project that I've uploaded. Currently, I've solved this problem by adding
leftAxis.axisMinimum = 0

Thank you, This solution worked.

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