ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.43k stars 5.97k forks source link

Bar Chart Value Labels missing #5135

Open gabors opened 7 months ago

gabors commented 7 months ago

What did you do?

Create a Bar Chart view. Create a data set where all values are negative.

What did you expect to happen?

Expect the value labels to be rendered.

What happened instead?

Value labels do not always render. They may show up or disappear depending on the size of the chart view or containing view/window. Easy to see when running in a Mac app and dragging the window size bigger or smaller.

Only seems to happen when all values are negative. With positive bar charts seems to be fine.

DGCharts Environment

DGCharts version/Branch/Commit Number: Current and any previous Xcode version: 15.x and 14.x Platform(s) running DGCharts: iOS 15+ and macOS 12+

image image
ChrisColeTech commented 6 months ago

Same issue here.

It happens randomly. I've tried changing constraints, font sizes, leftAxis spaceTop/spaceBottom and nothing consistently works.

Charts 3.2.2

iPhone 11 Pro Simulator iOS 14.5 XCode 12.5 Swift 4

gabors commented 3 months ago

Please help us. Thanks @danielgindi

liuxuan30 commented 3 months ago

are you able to debug a little? it seems you could do this. normally just search for the value labels and see whether it goes into drawText. is it only happens on mac?

gabors commented 3 months ago

Hi @liuxuan30

I may find some time to debug. But not in the near future.

But it happens in iOS as well. Like I said it's easier to replicate on Mac. Mac Catalyst in my case. Labels disappear randomly depending on the chart view frame size. It's really easy to see on Mac as you can freely resize the app window.

On iOS it's a lottery. They can disappear depending what negative values you have. May disappear in portrait but not landscape and vice versa.

You should be able to replicate quite easily.

cc-signet commented 3 months ago

Same issue here.

It happens randomly. I've tried changing storyboard constraints, font sizes, leftAxis spaceTop/spaceBottom and nothing consistently works.

Charts 3.2.2

iPhone 11 Pro Simulator iOS 14.5 XCode 12.5 Swift 4

Upgraded to version 4.1.0 and the issue still remains.

It seems to only happen when all values are negative, and it is still random.

Expected result: Expected

Actual result: Actual

iPhone 15 Pro Simulator iOS 17.4 XCode 15.3 Swift 4

cc-signet commented 3 months ago

are you able to debug a little? it seems you could do this. normally just search for the value labels and see whether it goes into drawText. is it only happens on mac?

Thank you for the suggestion. This actually helped!

Starting from drawText,

I was able to determine that the bug is actually caused by the following line of code inside of the drawValues(context: CGContext) method in the BarChartRenderer.swift class:

` Swift

                    guard viewPortHandler.isInBoundsY(rect.origin.y),
                        viewPortHandler.isInBoundsLeft(x)
                        else { continue }

`

image

And when I comment that code out, it displays the values as expected:

image

Before: Before

After: Fixed

If someone could shed some light on this code, and tell us what its doing (and why it is causing this bug) that would be appreciated. Otherwise, its working fine without this code and hopefully it is fixed in the future.