cocoa - Coreplot 图例在图框之外绘制

标签 cocoa core-plot

我有 OS X 应用程序的图表,可以随窗口调整大小。我预计当宽度减小得足够多时,图例将被截断或剪裁。然而,它溢出到绘图区域之外,如下所示。理想情况下,我希望图例截断或至少剪辑内容。如何做到这一点?

我的图例设置如下

- (void)configureLegend
{
    // 1 - Get graph instance
    CPTGraph *graph = self.graphHostingView.hostedGraph;
    // 2 - Create legend
    CPTLegend *theLegend;
    if (!theLegend) {
        theLegend = [CPTLegend legendWithGraph:graph];
    }

    //Configure Text
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
    textStyle.color = [CPTColor colorWithComponentRed:0.612f green:0.612f blue:0.612f alpha:1.00f];
    textStyle.fontName = @"HelveticaNeue";
    textStyle.fontSize = 12.0f;
    theLegend.textStyle = textStyle;

    // 3 - Configure legend
    theLegend.numberOfColumns = 1;
    theLegend.fill = nil;
    theLegend.borderLineStyle = nil;
    theLegend.swatchSize = CGSizeMake(10.0, 10.0);
    theLegend.swatchCornerRadius = 5.0f;
    // 4 - Add legend to graph
    graph.legend = theLegend;
    graph.legendAnchor = CPTRectAnchorLeft;
    CGFloat viewWidth = self.graphHostingView.bounds.size.width;
    CGFloat legendPadding = (viewWidth * 0.3) + self.pieChart.pieRadius + (viewWidth * 0.05);
    graph.legendDisplacement = CGPointMake(legendPadding, 0.0);
}

Legend Not Clipping

最佳答案

确保图形遮盖了其子图层。使用 masksToBounds 剪裁到边框线的外部,或使用 masksToBorder 剪裁到边框的内边缘。

关于cocoa - Coreplot 图例在图框之外绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27322344/

相关文章:

cocoa - 第一次绘制时 CALayers 未显示

iphone - 如何用颜色填充图形区域

objective-c - 为什么当我选择标题时我的 NSTableView 会变成蓝色?

objective-c - 使用 NSTimer 传递原始参数的正确方法

objective-c - 找到另一个 NSPoint 最接近哪个 NSPoint 的最佳方法是什么?

objective-c - 修改我的 CorePlot 代码以将日期放在 X 轴上

objective-c - Markdown 到 uiview/nsview

objective-c - 输出设备的类型(耳机等)

ios - 在核心图中添加其他x轴

ios - 使用Core Plot对饼图切片进行动画处理