Core plot pieChart中的图例标题格式不正确

时间:2014-04-16 12:17:52

标签: ios core-plot

我用它来显示图例标题:

-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
    NSLog(@"titles: %@", list[index]);
    return list[index];
}

我可以看到控制台输出:

titles: Entertaiment
titles: Entertaiment
titles: Entertaiment
titles: Entertaiment

.
.
.

但在iPhone上我看到了这一点:

enter image description here

为什么会发生这种情况,我该如何解决?

(CorePlot_1.5.1 Xcode 5.1 iOS 7.1)

修改

我的configureLegend方法如下所示。我将图例添加到scrollView

-(void)configureLegend {

    // 1 - Get graph instance
    graph = self.hostView.hostedGraph;

    // 2 - Create legend
    CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];

    // 2 - Set up text style

    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
    textStyle.color = [CPTColor blackColor];
    textStyle.fontName = @"Helvetica-Thin";
    textStyle.fontSize = 15.0f;

    [[graph legend] setTextStyle:(CPTTextStyle *)textStyle];

    theLegend.numberOfColumns = 2;
    theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
    theLegend.borderLineStyle = nil;
    theLegend.cornerRadius = 5.0;
    theLegend.hidden = NO;

    // 4 - Add legend to graph
    graph.legend = theLegend;
    graph.legendAnchor = CPTRectAnchorBottom;

    CGFloat legendPadding = 1.0;
    graph.legendDisplacement = CGPointMake(legendPadding, 0.0);


    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(-5, 0, _secondView.frame.size.width, _secondView.frame.size.height + 20)];


    scrollView.clipsToBounds = YES;
    scrollView.userInteractionEnabled = YES;

    scrollView.contentSize = CGSizeMake(_secondView.frame.size.width + 100, _secondView.frame.size.height + 400); //(scrollView.contentSize.width, 1000)

    for (UIView *subView in self.secondView.subviews)
    {
         [subView removeFromSuperview];
    }

    [scrollView.layer addSublayer:self.hostView.hostedGraph.legend];
    [self.secondView addSubview:scrollView];
    scrollView.showsVerticalScrollIndicator = YES;
    scrollView.showsHorizontalScrollIndicator = NO; 
}

1 个答案:

答案 0 :(得分:0)

由于您手动添加了图例视图,因此您可以查看"反向视图问题"。 实际上,他们在“反转”视图中绘制了情节,他们反过来。如果我记得很清楚,他们这样做是因为坐标(x,y)使其更容易理解,因为(x = 0,y = 0)应该在左上角,这不是你通常的图形。 因此,解决方案是扭转它:

[[yourTitleView layer] setTransform:CATransform3DMakeRotation(M_PI, 1, 0, 0)];