Draw a target/goal in chart?


#1

On my chart I want to add a target line, which would just be a completely horizontal line at the “goal”.  I’d like for that line to be a dashed line, instead of a solid line.   How would I accomplish such a thing?


#2

You can add a solid line to your chart using the SChartAnnotation class. However, currently we only provide factory methods for creating solid bands and lines. This means that to create a dotted line you will have to do some more work.  

You will need to write UIView subclass that draws a dotted line within it that spans the full width of your chart. Then, you could then add an instance of this dotted line UIView as a sub-view on an SChartAnnotation added to your chart which you could then add to your chart.

Since annotations are always anchored to a point on your chart, you would need to update the position of the annotation whenever your chart pans/zooms (using the currentRange property on your X-axis), so that it is always starting from the left most visible value, and stays spanning the full width of your chart.

I understand that this is quite a bit more work than just simply adding a solid line annotation to your chart, so I have forwarded this feature as a suggestion to our development team. They will review it and come to a decision wether as to include it in a future release. I hope my advice helped :laughing:.

Jan


#3

Well, I don’t own the Premium chart version, so no annotations  :cry:

I did manage to get a solid line though via just adding a second series, and setting the same y value for every data point.  Doesn’t support the ‘dashed’ look though.  


#4

Ah, you’re right you would need premium for that! Glad you managed to get something working though.