【问题标题】:Core Plot Graphs : X axis Label Truncation Issue核心绘图:X 轴标签截断问题
【发布时间】:2017-03-24 11:23:30
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c core-plot


    【解决方案1】:

    您需要结合以下几件事。您选择哪一个取决于您想要达到的外观。

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

    【讨论】:

    • 嗨,埃里克,感谢您的建议,但右填充的增加不起作用,我的意思是减少或增加都不会导致任何变化/效果.. 我们是否在这里遗漏了任何东西以进行填充上班……
    • 再问,有什么办法可以减小X轴标签的字体大小?
    • 使用不同的labelTextStyle 更改标签文本的大小、颜色或其他样式属性。请编辑问题并添加您的设置代码,以便我们查看应用填充的位置,以便我们提供建议。
    • 好的,我将编辑关于图形配置部分的问题。
    • 我没有看到任何地方设置了轴文本样式。更改 labelTextStyle 以重新格式化轴标签。
    【解决方案2】:

    在xAxis,可以设置标签左对齐。

    【讨论】:

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