1

How to create a limit line for each bar chart in iOS swift. I'm using Chart Library

Here is my code: -

var chartView: BarChartView!
var entries: [BarChartDataEntry] = []
var data: [Double]?

func draw() {
    for index in 0..<data.count {
        let dataEntry = BarChartDataEntry(x: Double(index), y: data[index])
        entries.append(dataEntry)
    }

    let chartDataSet = BarChartDataSet(values: entries, label: "")
    let chartData = BarChartData(dataSet: chartDataSet)
    chartData.setValueFont(UIFont(name: "Roobert-SemiBold", size: 12.0))
    chartData.barWidth = 0.3
    chartView.data = chartData

    var limitLine = ChartLimitLine()
    limitLine = ChartLimitLine(limit: 15, label: "15")
    limitLine.lineColor = .blue
    limitLine.valueTextColor = .blue
    limitLine.lineDashLengths = [3.0]
    chartView.leftAxis.addLimitLine(limitLine)

    var limitLine = ChartLimitLine()
    limitLine = ChartLimitLine(limit: 12, label: "12")
    limitLine.lineColor = .orange
    limitLine.valueTextColor = .orange
    limitLine.lineDashLengths = [3.0]
    chartView.leftAxis.addLimitLine(limitLine)
}

Output: -

Requirement: -

please refer above images,

For example, the limit line here is starting from the highest bar to the lowest bar but I would like to show this limit line only for the average bar. Is there a way?

0 Answers0