Adding annotations when using a category axis


I’m trying to add some annotations to a column chart where the x axis is a category axis and the y axis is a number axis.

The first requirement is to draw a horizontal band above each column showing a calculated difference. I’ve tried creating a horizontal band then giving it an xValue and setting strethToBoundsOnX to NO but the result is a thin line in the middle of the bar, it doesn’t stretch to the width of the bar. Is this possible? The code I’m using is

SChartAnnotationZooming *diffBarAnnotation = [SChartAnnotationZooming horizontalBandAtPosition:@(value) andMaxY:@(value * 1.1) withXAxis:chart.xAxis andYAxis:chart.yAxis withColor:[UIColor greenColor]];
diffBarAnnotation.xValue = name;
diffBarAnnotation.stretchToBoundsOnX = NO;

The other requirement is to show a horizontal line above each column and I have exacly the same issue - the line either fills the width of the chart (strechToBoundsOnX = YES) or shows as a dot in the middle of the column (strechToBoundsOnX = NO)

Is there any way of making the annotations match the width of the column? Can I get the width of the column and change the frame of the annotation?



Greetings Program!

This post might help with determining the column width:

You could set the frame or bounds of the annotation; in the Adding Annotations sample app, I changed the the frame of the text label:

// rotate the text by 90 degrees
releaseLabel.transform = rotationTransform;
releaseLabel.position = SChartAnnotationAboveData;

releaseLabel.label.backgroundColor = [UIColor blueColor];
releaseLabel.label.frame = CGRectMake(releaseLabel.frame.origin.x, releaseLabel.frame.origin.y, releaseLabel.frame.size.height, releaseLabel.frame.size.width * 2);

[_chart addAnnotation:releaseLabel];

And the frame of the SChartAnnotationZooming annotation in addCustomAnnotation:

an.bounds = CGRectMake(0,0,50,50);
// or
an.frame = CGRectMake(0, 0, 50, 50);

an.position = SChartAnnotationBelowData;
an.stretchToBoundsOnX = NO;

You may need to tweak the following values as well when instantiating the diffBarAnnotation.

horizontalBandAtPosition:@(value) andMaxY:@(value * 1.1)