0

I am using Charts API and implementing chart. I am new in that and there is no proper documentation for Swift 3.

I tried and implemented but don't know how to remove that negative scale for y. How can I start my graph from 0 only, so it does not show a negative y scale?

Below is my code:

fileprivate func ChartViewProperty() {

    barChartView.xAxis.labelPosition = .bottom
    barChartView.chartDescription?.text = ""
    barChartView.fitBars = true
    barChartView.pinchZoomEnabled = false
    self.barChartView.rightAxis.enabled = false
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce)

    barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
    barChartView.xAxis.granularity = 1
    value.append([jan,feb,mar,apr,may,jun,jly,aug,sep,oct,nov,dec])
    setChart(dataPoints: months, values: value)
}. 

Image:

enter image description here

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Kishor Pahalwani
  • 1,010
  • 1
  • 23
  • 53

3 Answers3

1

Try setting axisMinValue Property

I guess barChartView.xAxis.axisMinValue

0
fileprivate func ChartViewProperty() {

    //barChartView.xAxis.drawGridLinesEnabled = false
    barChartView.xAxis.drawAxisLineEnabled = false

    //barChartView
    barChartView.xAxis.drawLabelsEnabled = true

    //Space between x axis
    barChartView.xAxis.spaceMin  = 1.0
    barChartView.xAxis.spaceMax  = 1.0

    //Left axis bottom
    barChartView.leftAxis.spaceBottom = 0.0

    //Label Position
    barChartView.xAxis.labelPosition = .bottom

    //Description
    barChartView.chartDescription?.text = ""

    //Fit Bar
    barChartView.fitBars = false

    //Pinch Zoom
    barChartView.pinchZoomEnabled = false

    //Right x axis enabled
    self.barChartView.rightAxis.enabled = false

    //Animate barchart
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce)
}
Kishor Pahalwani
  • 1,010
  • 1
  • 23
  • 53
0

This line removes all negative values from the bar chart:

chartView.rightAxis.axisMinimum = 0
de.
  • 7,068
  • 3
  • 40
  • 69