1

I have created a simple bar chart with some data all in the same range( between 20 and 30).

the generated chart displays the data starting at just bellow 20 to just above 30.

How can I render the graph to display the data from 0 on the y axis

included below is my trial code and an image of the resulting graph

import UIKit import Charts

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    generateChartData()
    setChart()    }

let temperatures = [22.1, 21.5, 27.3, 27.5, 30.0, 22.2,27.6, 20.0, 23.5]
let colours = [ "red", "blue", "green", "orange", "grey", "yellow", "black", "white"]
var combinedData:[BarChartDataEntry] = []

@IBOutlet weak var barChart: BarChartView!

func setChart() {
    
    let chartDataSet = BarChartDataSet(entries: combinedData, label: "interesting data")
    let chartData = BarChartData(dataSet: chartDataSet)
    barChart.data = chartData
}

func generateChartData() {
    for i in 0..<colours.count {
       let thisEntry = BarChartDataEntry(x: Double(i), y: temperatures[i], data: colours[i])
        combinedData.append(thisEntry)
    }
}

}bar graph displaying truncated bars

francois
  • 13
  • 3

1 Answers1

0

You can set the axises minimum value, like this:

barChart.leftAxis.axisMinimum = 0
barChart.rightAxis.axisMinimum = 0

Or even not zero, but some minus value. Added here left and right axis for simplicity if you disable one of them.

Denis Kozhukhov
  • 1,205
  • 8
  • 16