核心图创建动态Y轴和显示图非常清晰

时间:2013-05-27 10:10:45

标签: iphone ios5 core-plot

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

例如,我的数据适用于Y轴99.7,99.3,99.2,99.0,100。

所以我希望y轴min从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。 请帮帮我

2 个答案:

答案 0 :(得分: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以控制标签的外观。

答案 1 :(得分:1)

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

 x_axis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(yMin);