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

BarGraph - 0 values - Bar Offset #2528

Closed
denebj opened this issue Jun 16, 2017 · 2 comments
Closed

BarGraph - 0 values - Bar Offset #2528

denebj opened this issue Jun 16, 2017 · 2 comments

Comments

@denebj
Copy link

denebj commented Jun 16, 2017

I have an issue of the weird spacing when I have 0 values in my bar graph.

So I just created a default bar chart with a 0 value and I have the issue - I tried to get as close as possible to a simple bar to see what was the issue.

It looks like the demo but a soon as I put a 0 value , I get a padding.

Here the sample code :

@IBOutlet var barChartView: BarChartView!

func viewDidLoad() {
super.viewDidLoad()
self.styleChart()
self.configureChart()
}

internal func styleChart() {
    self.barChartView.xAxis.labelPosition = .bottom
    self.barChartView.xAxis.labelCount = 2
}

internal func configureChart() {
    
    var xValues = [String]()
    var entries: [ChartDataEntry] = Array()

     xValues.append("TEST 5")
     xValues.append("TEST 0")
     entries.append(BarChartDataEntry(x: Double(0), y: Double(5) ))
     entries.append(BarChartDataEntry(x: Double(1), y: Double(0) ))
    
    
    let dataSet = BarChartDataSet(values: entries, label: "")
    dataSet.drawIconsEnabled = false
    dataSet.drawValuesEnabled = true

    let formatter = NumberFormatter()
    formatter.numberStyle = NumberFormatter.Style.decimal
    dataSet.valueFormatter = DefaultValueFormatter(formatter: formatter)

    let barChartData = BarChartData(dataSet: dataSet)
    barChartData.barWidth = 0.2        
     self.barChartView.data = barChartData
}

Pretty straightforward.

It is a bug ?

Issue with 0 :
27046056-aa244e9c-4f68-11e7-9dba-eb8910082ce4

No 0 :
27046346-acd37e6e-4f69-11e7-9403-b18616dd74ef

@liuxuan30
Copy link
Member

liuxuan30 commented Jun 20, 2017

not really. The y axis range is calculated by your data range. To keep your chart inside the canvas, the axis range will be larger than your data range. Check out computeAxisValues() to have a good understanding how it generate the ranges.

If you want the y axis always starts from 0, set leftAxis.axisMinimum = 0

@denebj
Copy link
Author

denebj commented Jun 20, 2017

Ah ok :) Thank you for the explanation !

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