4
votes

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. limit line not appearing

  • With a target of 80, and the last value as 79: the limit line does show. limit line appearing

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

2
i think you must set the chart to full view or maybe use scaling so it will give you complete view with ChartLimitLine - AFTAB MUHAMMED KHAN
Ok but do you know how to do that? - Frédéric Adda
checking myself - AFTAB MUHAMMED KHAN
did you try unzoom via pinch gesture - AFTAB MUHAMMED KHAN
No, because this graph is supposed to be static. - Frédéric Adda

2 Answers

0
votes

I'm not sure I understood your propose, but I think you should set axisMaximum to 80 or over it. You say your graph is static , so maybe you can limit left Y Axis's range in 40 ~ 90 by set axisMinimum and axisMaximum.

If you just want to show the all chart without scale, just call

chart.setScaleEnabled(false)
-1
votes
  /// if the chart is fully zoomed out, return true
    open var isFullyZoomedOut: Bool
    {
        return isFullyZoomedOutX && isFullyZoomedOutY
    }

    /// - returns: `true` if the chart is fully zoomed out on it's y-axis (vertical).
    open var isFullyZoomedOutY: Bool
    {
        return !(_scaleY > _minScaleY || _minScaleY > 1.0)
    }