【问题标题】:iOS core plot X - Axis Labels not visibleiOS 核心绘图 X - 轴标签不可见
【发布时间】:2014-03-19 07:06:19
【问题描述】:

我在 iOS 中使用 CorePlot 来显示图表,我可以显示 y 轴自定义标签,但无法查看 X 轴自定义标签。

这是我用来显示 X 轴自定义标签的代码..

 // 2 - Get axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;

// 3 - Configure x-axis
CPTAxis *x = axisSet.xAxis;
x.titleTextStyle = axisTitleStyle;
x.titleOffset = 0.0f;
x.axisLineStyle = axisLineStyle;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.labelTextStyle = axisTextStyle;
x.majorTickLineStyle = axisLineStyle;
x.majorTickLength = 4.0f;
x.minorTickLength = 0.0f;
x.tickDirection = CPTSignNegative;

//    Draw labels
NSArray *xCustomTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:2],[NSDecimalNumber numberWithInt:3],[NSDecimalNumber numberWithInt:4],[NSDecimalNumber numberWithInt:5],[NSDecimalNumber numberWithInt:6],[NSDecimalNumber numberWithInt:7] ,nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E",@"F",@"G", nil];
NSUInteger labelLocation = 0;
NSMutableArray *xCustomLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in xCustomTickLocations) {
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    [xCustomLabels addObject:newLabel];
}

x.axisLabels = [NSSet setWithArray:xCustomLabels];
x.majorTickLocations = [NSSet setWithArray:xCustomTickLocations];

请帮助我解决我做错的事情。刻度线可见,但标签不可见。

【问题讨论】:

    标签: ios core-plot


    【解决方案1】:

    我发现了问题,实际上标签正在被绘制但超出了框架。

    所以我只是增加了图形底部填充。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      • 1970-01-01
      相关资源
      最近更新 更多