- (BOOL)legend:(CPTLegend *)__unused legend shouldDrawSwatchAtIndex:(NSUInteger)idx forPlot:(CPTPlot *)__unused plot inRect:(CGRect)rect inContext:(CGContextRef)context {
SWGAccountInfo *account = [_dataModel.chartList objectAtIndex:idx];
CGColorRef color = [UIColor sc_colorForPieChart:[account.balanceInfo.currency.typeCode unsignedIntegerValue]].CGColor;
CGContextSetFillColorWithColor(context, color);
if(_dataModel.chartList.count == 4) {
switch (idx) {
case 0: {
rect = CGRectMake(48, 45, 16, -9);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:3.0];
[bezierPath fill];
CGContextFillRect(context, rect);
return NO;
break;
}
case 1: {
NSLog(@"%f, %f", legend.position.x, legend.position.y);
rect = CGRectMake(133, 45, 16, -9);
UIBezierPath *bezierPath1 = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:3.0];
[bezierPath1 fill];
CGContextFillRect(context, rect);
return NO;
break;
}
case 2: {
NSLog(@"%f, %f", legend.position.x, legend.position.y);
rect = CGRectMake(224, 45, 16, -9);
UIBezierPath *bezierPath2 = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:3.0];
[bezierPath2 fill];
CGContextFillRect(context, rect);
return NO;
break;
}
case 3: {
NSLog(@"%f, %f", legend.position.x, legend.position.y);
rect = CGRectMake(315, 45, 16, -9);
UIBezierPath *bezierPath3 = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:3.0];
[bezierPath3 fill];
CGContextFillRect(context, rect);
return NO;
break;
}
default:
return NO;
break;
}
}
return NO;
My current result is:
This is nice if I test with some data, but when I use some other data I get this:
Is there any possible way to get the center of the displaced legend at some index's middle so it could always be drawn at the middle of the legend