'IOS Charts - Limit Line appears twice after refreshing data

I'm using iOS Charts by Daniel Gindi on Github. I'm presenting a chart with a Limit Line and all is well. When I add data to the chart, everything is working fine, yet the Limit Line appears twice. I've tried reinitializing the Limit Line:

    var limitLine = ChartLimitLine()
    limitLine = ChartLimitLine(limit: 
    self.averagePointsArray.average, label: "This weeks average")
    self.barChartView.rightAxis.addLimitLine(limitLine)
    self.setChart()

I've also tried to use the methods:

barChartView.clear() barChartView.clearValues()

Again, the data is chart is working fine. Strange.

enter image description here



Solution 1:[1]

The documentation on iOS Charts is rather scarce as it was ported from an Android library (which is fully documented)

I came across this method that enables the removal of the Limit Line

barChartView.rightAxis.removeLimitLine(self.limitLine)

I remove it and add it back with the updated Limit Line value.

Solution 2:[2]

Use

barChartView.rightAxis.removeAllLimitLines()

Before addLimitLine

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Muldoon
Solution 2 Froylan Almeida