如图所示,X轴标签被截断。
我正在尝试这个
[xRange expandRangeByFactor:CPTDecimalFromDouble(1.05)]
但我仍然无法成功。如果有任何方法可以避免这种截断,请告诉我。
这会配置图表,
-(void)configureGraph {
CPTGraph *graph = [[CPTXYGraph alloc initWithFrame:self.hostView.bounds];
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
self.hostView.hostedGraph = graph;
graph.paddingLeft = 0;
graph.paddingRight = 0;
graph.paddingTop = 0;
graph.paddingBottom = 0;
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineWidth = 1.0;
borderLineStyle.lineColor = [CPTColor colorWithCGColor:[UIColor whiteColor].CGColor];
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor blackColor];
titleStyle.fontName = [UIFont flukeFontBoldName];
titleStyle.fontSize = 16.0f;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -15.0f);
[graph.plotAreaFrame setPaddingLeft:kPaddingLeft];
[graph.plotAreaFrame setPaddingBottom:kPaddingBottom];
[graph.plotAreaFrame setPaddingTop:kPaddingTop];
[graph.plotAreaFrame setPaddingRight:kPaddingRight];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
}
-(void)configureAxes
{
CPTGraph *graph = self.hostView.hostedGraph;
// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.5;
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.6] colorWithAlphaComponent:0.75];
CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
x.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
x.majorGridLineStyle = majorGridLineStyle;
x.minorGridLineStyle = minorGridLineStyle;
x.preferredNumberOfMajorTicks = 4;
x.minorTicksPerInterval = 1;
// pin axis to bottom
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
// Y axis
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
y.majorIntervalLength = CPTDecimalFromDouble(20.0f);
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.preferredNumberOfMajorTicks = kCorePlotYAxisPreferredTickLocationCount;
y.minorTicksPerInterval = 0;
// Pin axis to left
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
}
答案 0 :(得分:0)
在xAxis中,您可以将标签对齐设置为左侧。
答案 1 :(得分:0)
您需要对以下内容进行一些组合。您选择哪一个取决于您想要达到的外观。
xRange
的长度,以便从右边缘移动最后一个数据值。