Change the appearance of the Core Plot title

I would like to use a simple black background for my pie chart that I am creating using Core Plot. I have a nice rendering of the chart, but the title is in black by default, which is difficult to see against a black background. I know this is showing because when I change the theme I can see it in black. Can anyone tell me how to change the color of the text like it did with the data labels?

Here is a snippet of my code ...

    graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
    CPTGraphHostingView *hostingView = (CPTGraphHostingView*)self.view;
    hostingView.hostedGraph = graph;

    CPTPieChart *pieChart = [[CPTPieChart alloc] init];
    pieChart.dataSource = self;
    pieChart.pieRadius = 80.0;
    pieChart.identifier = @"PieChart1";
    pieChart.startAngle = M_PI_4;
    pieChart.sliceDirection = CPTPieDirectionCounterClockwise;

    [graph addPlot:pieChart];
    graph.title = @"Proportion of Sessions per Sport";


-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
    static CPTMutableTextStyle *whiteText = nil;
    if (!whiteText) {
        whiteText = [[CPTMutableTextStyle alloc] init];
        whiteText.color = [CPTColor whiteColor];

    CPTLayer *layer = [[CPTLayer alloc] initWithFrame:CGRectMake(50, 50, 100, 20)];
    CPTTextLayer *newLayer = nil;
    newLayer = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [pieLabels objectAtIndex:index]] style:whiteText];
    [layer addSublayer:newLayer];
    return newLayer;

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
    return [self.pieData count];

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
    return [self.pieData objectAtIndex:index];

-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
    return [NSString stringWithFormat:@"Pie Slice %u", index];


Thanks a lot in advance for any help / tips / links offered ...


source to share

1 answer

I found an answer that was staring me in the face all along in the Core Plot sample code ...

For someone who stumbled upon this question, here's the answer:

CPTMutableTextStyle *whiteText = [CPTMutableTextStyle textStyle];
    whiteText.color = [CPTColor whiteColor];
    graph.titleTextStyle = whiteText;
    graph.title = @"Your Title Here...";




All Articles