ios - 如何为核心图图表的轴提供标签?

标签 ios core-plot

我正在使用 Core Plot 框架,并尝试完成示例应用程序。有使用这个框架的教程吗?

具体来说,如何为图表中的 X 轴和 Y 轴提供标签?

最佳答案

不幸的是,鉴于该框架的 API 尚未稳定,因此没有那么多教程,而且一些现有的教程已经过时了。示例应用程序确实是了解如何使用该框架的最佳来源。

例如,要提供自定义轴标签,请查看 CPTestApp-iPhone 的 CPTestAppBarChartController.m 源文件。该示例中的条形图具有由以下代码定义的自定义 X 轴标签:

// Define some custom labels for the data elements
x.labelRotation = M_PI/4;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
    CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    newLabel.offset = x.labelOffset + x.majorTickLength;
    newLabel.rotation = M_PI/4;
    [customLabels addObject:newLabel];
    [newLabel release];
}

x.axisLabels =  [NSSet setWithArray:customLabels];

首先,将轴标签策略设置为 CPAxisLabelingPolicyNone,让框架知道您将提供自定义标签,然后创建一个标签数组及其相应位置,最后分配该数组X 轴上的 axisLabels 属性的标签。

关于ios - 如何为核心图图表的轴提供标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2904562/

相关文章:

Core Plot 中的 iOS 水平条形图显示两个值

ios - 未捕获的异常 'NSInvalidArgumentException',原因: 'Receiver .. has no segue'

ios - 如何设置计时器来启用/禁用按钮

iphone - UITableViewCell 的 viewDidAppear

ios - 尽管请求调用,但单击按钮时仍会暴露 UI

objective-c - 带静态轴的核心图

ios - 在作为 Window subview 的 View 中添加 subview

plot - CorePlot 图中的外边距

core-plot - xcode 10 coreplot消息传递不合格的id

swift - 使用核心图使用自定义标签绘制散点图