I'm using the "Charts" library (by Daniel Gindi) on iOS.
I draw a LineChartView (no issue there), and want to add a limit line to represent the target value:
let targetLine = ChartLimitLine(limit: targetValue, label: "")
lineChartView.leftAxis.addLimitLine(targetLine)
The issue I have is: if the y-values of my chart are too far from the target, the limit line just doesn't show on the chart.
Examples:
With a target of 80, and the last value as 59: the limit line does not show.
With a target of 80, and the last value as 79: the limit line does show.
How can I make sure that the limit line will always appear, no matter what the y-values are?
Appendix : here is the rest of my drawing code, it's very standard:
let chartView = LineChartView()
chartView.backgroundColor = UIColor.whiteColor()
chartView.dragEnabled = false
chartView.doubleTapToZoomEnabled = false
chartView.pinchZoomEnabled = false
chartView.highlightPerTapEnabled = false
chartView.descriptionText = ""
chartView.legend.enabled = false
chartView.rightAxis.enabled = false
// Set y axis
let yAxis = chartView.leftAxis
yAxis.removeAllLimitLines()
yAxis.drawZeroLineEnabled = true
yAxis.drawLimitLinesBehindDataEnabled = true
yAxis.valueFormatter = yValuesFormatter
// Set x axis
let xAxis = chartView.xAxis
xAxis.labelPosition = .Bottom
xAxis.drawLabelsEnabled = true
xAxis.drawLimitLinesBehindDataEnabled = true
xAxis.avoidFirstLastClippingEnabled = true
// Create a new dataset
let dataSet = LineChartDataSet(yVals: entries, label: "")
dataSet.drawValuesEnabled = false
dataSet.lineWidth = 2
dataSet.colors = [UIColor.customBlue]
dataSet.circleRadius = 5
dataSet.circleColors = [UIColor.customBlue]
dataSet.drawCircleHoleEnabled = false
dataSet.fillColor = UIColor.cityzenAccent
dataSet.fillAlpha = 0.5
dataSet.drawFilledEnabled = (chartType == .linefill) ? true : false
let data = LineChartData(xVals: xValues, dataSets: [dataSet])
chartView.data = data
The code for the limit lines takes place AFTER all that.
Thanks
I faced a similar problem, but in my case, I solved it by changing the maximum of the axis.
By changing the axis.maximum, you can always display the limitLine.
chartView.leftAxis.maximum = max(*limitLineValue*, *maxValueInDataSet*)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With