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

BarChartDataSet with only negative values doesn't call stringForValue on formatter #3030

Closed
jonseguin opened this issue Nov 22, 2017 · 2 comments

Comments

@jonseguin
Copy link

Hi !
I have a strange issue when trying to display a BarChartView.
When I make a BarChartDataSet with only negatives y-values, the valueFormatter "stringForValue" never get called. If I set at least one of the value positive, it works.

Here is my code (with an example of data) :

let dataSet = BarChartDataSet(values: [BarChartDataEntry(x:0, y:-4),
                                         BarChartDataEntry(x:1, y:-7),
                                         BarChartDataEntry(x:2, y:-10)], label: "")
barChartView.data = BarChartData(dataSet: dataSet) 
barChartView.data?.setValueFormatter(MyValueFormatter())

barChartView.pinchZoomEnabled = false
barChartView.dragEnabled = false
barChartView.setScaleEnabled(false)
barChartView.drawValueAboveBarEnabled = true
barChartView.drawBarShadowEnabled = false
barChartView.xAxis.enabled = false
barChartView.leftAxis.enabled = false
barChartView.rightAxis.enabled = false
barChartView.legend.enabled = false
barChartView.chartDescription = nil

class MyValueFormatter : NSObject, IValueFormatter {
    func stringForValue(_ value: Double, entry: ChartDataEntry, dataSetIndex: Int, viewPortHandler: ViewPortHandler?) -> String {
        return String(value)
    }
} 

Replace BarChartDataEntry(x:0, y:-4) by BarChartDataEntry(x:0, y:4), and the stringForValue is called.
Here, I set my custom IValueFormatter, but the issue also exist if I let the default one.

Am I missing a configuration property ?

@liuxuan30
Copy link
Member

take a look and debug at open override func drawValues(context: CGContext)() where it will call stringForValue(), check the if conditions

@jonseguin
Copy link
Author

Ok so it works now.
I am including the framework using Carthage, and it seems I just forgot to add the frameworks to the "Linked frameworks and librairies" on my project target.
It is weird that it is the only issue, since I used this framework a lot in this project.
Thanks !

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