2
votes

enter image description here

I have to draw a pie chart similar to this graph. I have to display data label  with text in two lines as mentioned in the image (Actual Count and the percent value) I want to know whether this is possible or not using core plot.  I am using the below delegate to to get either percent or the actual count, but not sure of how to get both values in that.  Any help would be highly appreciated.

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {

if([plot isKindOfClass:[CPTPieChart class]]) {
    static CPTMutableTextStyle *labelText = nil;
    if (!labelText) {
        labelText= [[CPTMutableTextStyle alloc] init];
        labelText.color = [CPTColor blueColor];

    }

    NSDecimalNumber *portfolioSum = [NSDecimalNumber zero];
    for (NSDecimalNumber *price in [[CPDStockPriceStore sharedInstance] dailyPortfolioPrices]) {
        portfolioSum = [portfolioSum decimalNumberByAdding:price];
    }
    NSDecimalNumber *countValue = [[[CPDStockPriceStore sharedInstance] dailyPortfolioPrices] objectAtIndex:index];
    NSString *labelValue = [NSString stringWithFormat:@"%@",countValue];
    CPTTextLayer *textLayer = [[CPTTextLayer alloc]initWithText:labelValue];
    return textLayer;
}
else {

    return nil;
}
}
1
This is not the off topic i want to know whether we can have two data labels one for value and one for percentage or not.Please help me - Gyanendra
It's a valid question. Please remove the on-hold status! - Mike Lischke
in case this question does not get opened again: the text layer allows to specify an attributed string. Try this and add \n where needed. You can also apply different styling for different parts in the string (as usual with attributed strings). - Mike Lischke
Thank for response Mike.I will try that - Gyanendra

1 Answers

0
votes

The text layer allows to specify an attributed string. Try this and add \n where needed. You can also apply different styling for different parts in the string (as usual with attributed strings). In fact, even a simple NSString will allow to split a lable into 2 lines. Just add \n where needed.