Draw chart annotation on top of axis


#1

Hi guys, I’m using a SChartAnnotation that is drawn above my data (annotation.position = SChartAnnotationAboveData). This annotation is supposed to be drawn on top of the y axis. However, the axis labels are drawn above the annotation. 

How can I draw the annotation on top of the axis labels? I couldn’t find anything related to that in the documentation, so if anyone has a clue, please shoot!

Cheers,

Max


#2

Hi Maximilian,

When you’re adding an annotation to the chart it is actually being added to one of two views, depending on whether you specify whether it should be above or below the data:

  • SChartAnnotationAboveData - the annotation is added as a subview that is in front of the data.
  • SChartAnnotationBelowData - the annotation is added as a subview that is behind your data.

Both of these views are children of the canvas, meaning that the tick marks & labels (which are subviews of the canvas) will be on top of them. The good news is you can simply add the annotations as a subview to the canvas yourself as soon as you’ve added the annotation:

[self.chart addAnnotation:myAnnotation];
[self.chart.canvas addSubview:myAnnotation];

Best regards,
Jan Akerman


#3

Thanks a lot Jan! Works like a charm.  :grin:


#4

No problem - glad I could help!