Core Plot 1.4 - 缩小Y轴和X轴标签之间的差距

时间:2014-10-17 13:10:07

标签: core-plot ios7.1 linechart

我正在尝试在我的iOS应用程序中实现Core plot。我面临很多问题。我将逐一列出。

1)当我的应用程序运行时,它应该以显示原点(0,0)的图形开始。因为目前它显示的地方是不可见的。然后我将布尔值更改为YES,然后我滚动并看到了原点上方的那条线。

"plotSpace.allowsUserInteraction = YES;

2)我可以手动调整X轴和Y轴线上2个点之间的空间。

以下是我按照Rey Wenderlich教程编写图表所尝试的代码,但正如您在图像中看到的那样,我只能看到一行。对于其他线路,我需要上下拖动以查看其他线路。特别感谢Eric Skroch和他的团队所做的精彩工作。 谢谢

enter image description here

////////   configure x-Axes

    CPTXYAxis *xAxis = [axisSet xAxis];

    CPTAxis *x = axisSet.xAxis;
    x.title = @"";
    x.titleTextStyle = axisTitleStyle;
    x.titleOffset = 5.0f;
    x.labelOffset = 5.0f;
    x.axisLineStyle = axisLineStyle;
    x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
    x.labelTextStyle = axisTextStyle;
    x.majorTickLineStyle = axisLineStyle;
    x.majorTickLength = 4.0f;
    x.labelRotation=45.0f;

    CGFloat dateCount = [dayArray count];
    NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
    NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
    NSInteger i = 0;
    for (NSString *date in dayArray)
    {

        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:date  textStyle:x.labelTextStyle];
        CGFloat location = i++;
        label.tickLocation = CPTDecimalFromCGFloat(location);
        label.offset = x.majorTickLength;
        if (label)
        {
            [xLabels addObject:label];
            [xLocations addObject:[NSNumber numberWithFloat:location]];
        }
    }
    x.axisLabels = xLabels;
    x.majorTickLocations = xLocations;

    //////// Configure Y-Axes

    CPTAxis *y = axisSet.yAxis;
    y.title = @"Hb";
    y.titleTextStyle = axisTitleStyle;
    y.titleOffset = -50.0f;
    y.axisLineStyle = axisLineStyle;
    y.majorGridLineStyle = gridLineStyle;
    y.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided;
    y.labelTextStyle = axisTextStyle;
    y.labelOffset = -0.0f;
    y.majorTickLineStyle = axisLineStyle;
    y.majorTickLength = 1.0f;
    y.minorTickLength = 1.0f;

    NSInteger majorIncrement = 2;
    NSInteger minorIncrement = 2;
    CGFloat yMax = 30.0f;  
    NSMutableSet *yLabels = [NSMutableSet set];
    NSMutableSet *yMajorLocations = [NSMutableSet set];
    NSMutableSet *yMinorLocations = [NSMutableSet set];
    for (NSInteger j = 0; j <= yMax; j += minorIncrement) {
        NSUInteger mod = j % majorIncrement;
        if (mod == 0) {
            CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", j] textStyle:y.labelTextStyle];
            NSDecimal location =CPTDecimalFromInteger(j);
            label.tickLocation =location;
            label.offset = -y.majorTickLength- y.labelOffset;
            if (label) {
                [yLabels addObject:label];
            }
            [yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
        } else {
            [yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
        }
    }
    y.axisLabels = yLabels;
    y.majorTickLocations = yMajorLocations;

1 个答案:

答案 0 :(得分:1)

如果要提供自定义轴标签,请更改labelingPolicy

x.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelingPolicy = CPTAxisLabelingPolicyNone;

自动标签政策会自动将刻度线位置和标签设置为&#34; nice&#34;基于绘图范围长度的值。提供的位置政策会自动在您提供的刻度位置创建标签。