核心图:X 轴标签截断问题

Core Plot Graphs : X axis Label Truncation Issue

如图所示,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];
}

在 xAxis 中,您可以将标签对齐方式设置为左对齐。

您需要结合执行以下操作。选择哪一个取决于你想要达到的外观。

  • 进一步增加 xRange 的长度以从右边缘移入最后一个数据值。
  • 增加绘图区域框架的右填充,使绘图区域的边缘进一步远离图形中文本被剪裁的边缘。