My way is to use filled line charts for background colours. You need to add two additional data sets, one for the red area and another for the green area. Also, you need to use custom FillFormatter
for filling a green area from top to a chart line.

In this exapmle, I define addFillingArea
function and use it for adding two additional data sets.
override func viewDidLoad() {
super.viewDidLoad()
// ...
let chartData = LineChartData()
addFillingArea(to: chartData, withColor: .red, xFirstValue: 0, xLastValue: 11, yValue: 6)
addFillingArea(to: chartData, withColor: .green, xFirstValue: 0, xLastValue: 11, yValue: 12, fillFormatter: TopToLineFillFormatter())
// add your data to chartData here
lineChartView.data = chartData
// ...
}
func addFillingArea(to chartData: ChartData, withColor color: UIColor, xFirstValue: Double, xLastValue: Double, yValue: Double, fillFormatter: IFillFormatter? = nil) {
let dataEntries = [
ChartDataEntry(x: xFirstValue, y: yValue),
ChartDataEntry(x: xLastValue, y: yValue)
]
let chartDataSet = LineChartDataSet(values: dataEntries, label: nil)
chartDataSet.setColor(.clear)
chartDataSet.drawValuesEnabled = false
chartDataSet.drawCirclesEnabled = false
chartDataSet.drawFilledEnabled = true
chartDataSet.fillAlpha = 0.5
chartDataSet.fill = Fill(CGColor: color.cgColor)
chartDataSet.fillFormatter = fillFormatter
chartData.addDataSet(chartDataSet)
}
class TopToLineFillFormatter: NSObject, IFillFormatter {
func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
var fillMin: CGFloat = 0.0
fillMin = CGFloat( dataProvider.chartYMax )
return fillMin
}
}