【问题标题】:How to add data label in pie chart and how to set frame/position for the legend screen of pieChart using core plot如何在饼图中添加数据标签以及如何使用核心图为饼图的图例屏幕设置框架/位置
【发布时间】:2013-01-21 09:38:56
【问题描述】:

我按照Rayenderlich CORE PLOT tutorial for PIE CHART 在iPhone应用程序上实现了一个饼图

http://www.raywenderlich.com/13269/how-to-draw-graphs-with-core-plot-part-1

这里我有一些问题,

我需要在图表上添加另一个数据标签(项目名称)

我尝试实现另一种方法,例如

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

在 CorePlot.h(我在应用程序中只找到一次)和我的 viewcontroller 类中的方法定义中,

但额外的数据标签尚未显示。

我需要将图例表移到图表下方而不是图表旁边 我尝试了 frame 和 legendDisplacement 但没有找到结果

【问题讨论】:

    标签: iphone objective-c core-plot


    【解决方案1】:

    数据标签与绘图数据相关联,饼图中的每个切片都有一个标签。在您的示例图片中,“每周报告”将是图表 title

    graph.title = @"Weekly Report";
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
    textStyle.color                = [CPTColor whiteColor];
    textStyle.fontName             = @"Helvetica-Bold";
    textStyle.fontSize             = 12.0;
    graph.titleTextStyle           = textStyle;
    graph.titleDisplacement        = 5.0;
    graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
    

    您可以使用legendAnchor 属性移动图例:

    graph.legendAnchor = CPTRectAnchorBottom;
    

    类似于titleDisplacementlegendDisplacement 设置图例与其在图表上的锚点之间的边距。

    【讨论】:

    • 是的,这是移动图例的正确方法,但山雀框架会固定在每个 legendAnchor 的特定位置。导致它与抓地力重叠
    • 我想将图例从图表中完全移动 10 个像素
    猜你喜欢
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多