gpt4 book ai didi

core-plot - CorePlot XAxis 标签不显示

转载 作者:行者123 更新时间:2023-12-01 07:16:08 25 4
gpt4 key购买 nike

嘿,
最近使用 CorePlot 但问题是,我设置的标签不显示,我能看到的一件事是主要和次要 TickLine,但也只在 x 线上方而不是下方。

这是我的代码:

subViewGraph=[[CPGraphHostingView alloc]init];

subViewGraph.frame=CGRectMake(0, 40, 320, 280);
subViewGraph.bounds=CGRectMake(0, 40, 320,280);
[self.view addSubview:subViewGraph];

graph = [[CPXYGraph alloc] initWithFrame:subViewGraph.bounds];

CPTheme *theme = [CPTheme themeNamed:kCPPlainWhiteTheme];
[graph applyTheme:theme];
subViewGraph.hostedGraph=graph;
graph.paddingBottom=40;

// Define some custom labels for the data elements
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x=axisSet.xAxis;

CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor redColor];
lineStyle.lineWidth = 2.0f;
x.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"2"]decimalValue];
x.minorTicksPerInterval = 4;
x.majorTickLineStyle = lineStyle;
x.minorTickLineStyle = lineStyle;
x.axisLineStyle = lineStyle;
x.minorTickLength = 5.0f;
x.majorTickLength = 10.0f;
x.labelOffset=3.0;
x.labelRotation = M_PI/4;
x.labelTextStyle.color=[CPColor blueColor];

NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0],
[NSDecimalNumber numberWithInt:2],
[NSDecimalNumber numberWithInt:4],
[NSDecimalNumber numberWithInt:6],
nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:axisSet.xAxis.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
[customLabels addObject:newLabel];
[newLabel release];
}

axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels];
axisSet.xAxis.title=@"Hello";

// Define the space for the bars.
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(150.0f)];
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(12.0f)];


// Bar plot
CPBarPlot *barPlot = [CPBarPlot tubularBarPlotWithColor:[CPColor yellowColor] horizontalBars:NO];
barPlot.dataSource = self;
barPlot.baseValue = CPDecimalFromString(@"0");
barPlot.barOffset = 1.0f;
barPlot.barWidth = 20.0f;
barPlot.identifier = @"BlueBarPlot";

[graph addPlot:barPlot toPlotSpace:plotSpace];

提前致谢。

最佳答案

我自己发现了。您必须添加一些不同的填充:

graph.plotAreaFrame.paddingBottom=40;

现在我的 xaxis 是可见的。

关于core-plot - CorePlot XAxis 标签不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5577651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com