I want to make ticks below the x-axis where the date labels (3.6., 7.6., 12.6. 17.6, 21.6., 26.6.) are (see image below). I'm using the iOS Charts library (https://github.com/danielgindi/Charts).
I managed to make ticks inside the graph by overriding the drawGridLine
method. All I did was change the beginning of the line segment from viewPortHandler.contentTop
to viewPortHandler.contentBottom - 5
. I.e. the grid line starts 5 pixels above the x-axis. However, when extending the grid line beyond the x-axis (viewPortHandler.contentBottom + 10
), the line still only gets drawn down to the x-axis, but not below. Can somebody point me in the right direction? How do I draw the vertical lines below the x-axis?
Here is my custom XAxisRenderer:
class XAxisRendererWithTicks: XAxisRenderer {
override func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat) {
guard
let viewPortHandler = self.viewPortHandler
else { return }
if x >= viewPortHandler.offsetLeft
&& x <= viewPortHandler.chartWidth
{
context.beginPath()
context.move(to: CGPoint(x: x, y: viewPortHandler.contentBottom - 5))
context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentBottom + 10))
context.strokePath()
}
}
}
The ticks appear, but I want them to be below the x-axis:
There is a similar question here, but its answers didn't really help me: Vertical lines at X Axis iOS-charts