maho125 maho125 - 2 months ago 12x
Swift Question

iOS Charts - How to set different color of exact vertical grid line than have others

In my application I'm using iOS Charts and I want to split my line chart to sectors by vertical grid line with different color than have others (someting like on chart below). I looked into documentation but I didn't find any solution how to do that. I know only how to change color of all grid lines at once. Thanks for any advice.

example chart


Here is my solution. I have array with x positions for vertical lines and in for loop I will add limit lines to chart.

for k:Int in 0 ..< limitLines.count {

let limitLine = ChartLimitLine()
limitLine.lineColor =
limitLine.limit = limitLines[k]
limitLine.lineWidth = 0.8


Here is resulting chart.

enter image description here


well.. this is not officially supported, but you could override drawGridLine() on x axis to do so, just need to know which grid line needs another color.