2

如何仅通过自动传递 yMin 和 yMax 图表来创建动态 y 轴并显示非常清晰。

例如,我的数据是 Y 轴 99.7, 99.3, 99.2, 99.0 ,100 。

所以我希望 y 轴最小值从 99 开始到 100,增量为 0.1,图表将显示得非常清晰。

我的代码片段如下 // 4 - 配置 y 轴

  y_monthly.title = lbl_M_HasDelay.text;
    y_monthly.labelAlignment = CPTAlignmentCenter;
    y_monthly.titleTextStyle = axisTitleStyle;
    y_monthly.titleOffset = -30.0f;
    y_monthly.axisLineStyle = axisLineStyle;
    y_monthly.majorGridLineStyle = gridLineStyle;
    y_monthly.labelingPolicy = CPTAxisLabelingPolicyNone;
    y_monthly.labelTextStyle = axisTextStyle;
    y_monthly.labelOffset = 16.0f;
    y_monthly.majorTickLineStyle = axisLineStyle;
    y_monthly.majorTickLength = 4.0f;
    y_monthly.minorTickLength = 2.0f;
    y_monthly.tickDirection = CPTSignPositive;
    NSMutableSet *yLabels = [NSMutableSet set];
    NSMutableSet *yMajorLocations = [NSMutableSet set];
    NSMutableSet *yMinorLocations = [NSMutableSet set];
    float minorIncrement=month_MaxY1/10;
    float majorIncrement = minorIncrement*2;
    float yMax = month_MaxY1;

    for (float j = minorIncrement; j <= yMax; j += minorIncrement)
    {
        float mod = fmodf(j, majorIncrement);
        if (mod == 0) {
            CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@""]textStyle:y_monthly.labelTextStyle];
            [label setAlignment:CPTAlignmentTop];
            NSDecimal location = CPTDecimalFromFloat(j);
            label.tickLocation = location;
            label.offset = -y_monthly.majorTickLength - y_monthly.labelOffset;
            if (label) {
                [yLabels addObject:label];
            }
            [yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
        } else {

            [yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromFloat(j)]];
        }
    }
    y_monthly.axisLabels = yLabels;
    y_monthly.majorTickLocations = yMajorLocations;
    y_monthly.minorTickLocations = yMinorLocations;

其中month_MaxY1 =100,而month_MinY1 =90.0。请帮我

4

2 回答 2

2

使用绘图空间设置 y 轴的范围:

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(99.0)
                                                length:CPTDecimalFromDouble(1.0)];

标记轴:

y_monthly.labelingPolicy = CPTAxisLabelingPolicyFixedInterval;
y_monthly.majorIntervalLength = CPTDecimalFromDouble(0.1);

这将沿 y 轴每隔 0.1 个单位制作刻度和标签。设置labelFormatterlabelTextStyle来控制标签的外观。

于 2013-05-27T13:58:29.560 回答
1

我想您的问题是让您的 X 轴显示在图表的 yMin 位置。你需要做的是:

 x_axis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(yMin);
于 2013-05-27T10:26:45.280 回答