【问题标题】:Has anyone worked out how to manually add labels into a Core-Plot (iPhone) graph?有没有人研究过如何手动将标签添加到核心图(iPhone)图中?
【发布时间】:2009-09-06 09:31:02
【问题描述】:

我为我的 iPhone 应用程序创建了一个简单的条形图,但是我想手动添加 x 轴标签。有没有人想出办法做到这一点?

我找到了 CPXYAxisSet.xAxis.axisLabels 属性,但是当我创建一个 NSSet 并使用以下方法分配它时:

axisSet.xAxis.axisLabelingPolicy = CPAxisLabelingPolicyNone;
NSSet *labels = [[NSSet alloc] initWithObjects:@"year 1", @"year 2" @"year 3", nil];
axisSet.xAxis.axisLabels = labels;

我得到一个:

*** Terminating app due to uncaught exception 'CALayerInvalid', reason: 'expecting model layer not copy: year 1'

错误。

谁有解决办法?

非常感谢。

【问题讨论】:

    标签: iphone frameworks core-plot labels


    【解决方案1】:

    我相信has been addressed 中的Core Plot mailing list。 axisLabels 属性接受一组 CPAxisLabel 对象(CALayer 的后代),而不是 NSStrings,这就是您得到上述异常的原因。

    要为每个自定义标签创建一个 CPAxisLabel,请使用类似于以下的代码:

    CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: customText]; 
    newLabel.tickLocation = [tickLocation decimalValue]; 
    newLabel.textStyle = x.axisLabelTextStyle; 
    newLabel.offset = x.axisLabelOffset + x.majorTickLength; 
    

    编辑(2010 年 1 月 18 日):Core Plot iPhone 测试应用程序中的条形图选项卡下现在提供了一个示例。

    【讨论】:

    • 非常感谢。我也会接受提示并前往 Core Plot 邮件列表 :-)
    • 没问题。我只是这里为数不多的有帐户的贡献者之一,所以你可能会在那里获得更多关于某个问题的关注。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    相关资源
    最近更新 更多