更改Core Plot饼图标题的外观 [英] Change the appearance of the title of a Core Plot pie chart

查看:115
本文介绍了更改Core Plot饼图标题的外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的饼图中使用纯黑色背景,我使用Core Plot生成。我有很好的图表渲染,但标题是在黑色背景上很难看到的默认黑色。我知道这是显示,因为当我改变主题时,我可以看到它黑色。任何人都可以告诉我如何改变文字颜色,就像我对数据标签做的那样?

I would like to use a plain black background to my pie chart which I generate using Core Plot. I have the chart rendering nicely but the title is in a default blackColor which is hard to see on a black background. I know it's displaying because when I change the theme I can see it in black. Can anyone tell me how to change the text colour as I 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];
}

非常感谢您提供的任何协助/建议/链接...

Many thanks in advance for any assistance/advice/links offered...

推荐答案

我在Core Plot示例代码中发现了它在我面前盯着我的全部答案...

I found the answer it was staring me in the face the whole time in the Core Plot sample code...

对于其他人在这个问题上磕磕绊绊的答案是:

For anyone else stumbling upon this question here is the answer:

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

这篇关于更改Core Plot饼图标题的外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆