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

Horizontal Bar Chart Rounding #676

Closed
jruston opened this issue Jan 13, 2016 · 1 comment
Closed

Horizontal Bar Chart Rounding #676

jruston opened this issue Jan 13, 2016 · 1 comment

Comments

@jruston
Copy link

jruston commented Jan 13, 2016

Hi,

I am seeing an issue with the horizontal bar chart. I am attempting to show a bar chart with 2 - 3 values in it. There's times on the X axis and doubles on the Y axis.

The issue occurs when all of the Y values are the same. For example, if there are 2 Y values and both of them are 1.67, it's incorrectly rounding them to 2. If one of the Y values was 1.67 and the other was 2, it works correctly.

screen shot 2016-01-13 at 16 54 00

This screenshot is taken where both values are 1.67.

screen shot 2016-01-13 at 16 55 00

This is taken where one value is 1.67 and the other is 2.

The number itself is very important in this application, rounding it to 2 would not work.

@liuxuan30
Copy link
Member

This is becuase it will calculate the digits it needs by default value formatter:

    internal func calculateFormatter(min min: Double, max: Double)
    {
        // check if a custom formatter is set or not
        var reference = Double(0.0)

        if (_data == nil || _data.xValCount < 2)
        {
            let absMin = fabs(min)
            let absMax = fabs(max)
            reference = absMin > absMax ? absMin : absMax
        }
        else
        {
            reference = fabs(max - min)
        }

        let digits = ChartUtils.decimals(reference)

        _defaultValueFormatter.maximumFractionDigits = digits
        _defaultValueFormatter.minimumFractionDigits = digits
    }

in your case only two equal values exist, and the reference would be 0, so the fraction digits are 0, that's why you see it's rounded, by the formatter.

What you can do is pass your valueFormater in dataSet, so you can get rid of the default formatter.

I won't consider it's a bug, because it's a default value foramtter, and it has a default logic to adjust its FractionDigits. There are always values can have more digits than maximumFractionDigits limit. So it's user's choice how to deal with it.

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