用单位标记核心图轴

时间:2013-09-30 22:13:35

标签: ios objective-c graph core-plot

我想知道如何将单位附加到动态的Core Plot轴,如下所示。不幸的是,这并不像循环标签和附加文本那么容易(我相信由于图层处理和渲染)。有谁知道如何解决这个问题?

    CPTXYAxis *x = axisSet.xAxis;
    x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(self.plotSpace1.xRange.minLimitDouble);//Where the Y Axis meets the X axis
    x.majorIntervalLength = CPTDecimalFromDouble(200.0);//Interval for X Axis
    x.minorTicksPerInterval = 0;
//    x.tickDirection = CPTSignNone;
//    x.axisLineStyle = axisLineStyle;
//    x.majorTickLength = 12.0;
//    x.majorTickLineStyle = axisLineStyle;
//    x.minorTickLength = 8.0;
    x.title = cYards;
    x.titleTextStyle = axisTitleTextStyle;
    x.titleOffset = 25.0;
    x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];


    // Label y with an automatic labeling policy.
    axisLineStyle.lineColor = [CPTColor greenColor];

    CPTXYAxis *y = axisSet.yAxis;
    y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
    y.preferredNumberOfMajorTicks = 11;
    y.majorIntervalLength = CPTDecimalFromDouble(100.0);
    y.minorTicksPerInterval = 0;
    y.tickDirection = CPTSignNegative;
    y.axisLineStyle = axisLineStyle;
    y.majorTickLineStyle = axisLineStyle;
    y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(self.plotSpace1.xRange.minLimitDouble);
    y.title = cInches;
    y.titleTextStyle = axisTitleTextStyle;
    y.titleOffset = 30.0;


    // Label y2 with an equal division labeling policy.
    axisLineStyle.lineColor = [CPTColor orangeColor];

    CPTXYAxis *y2 = [[CPTXYAxis alloc] init];
    y2.coordinate = CPTCoordinateY;
    y2.plotSpace = self.plotSpace2;
    y2.orthogonalCoordinateDecimal = CPTDecimalFromDouble(self.plotSpace1.xRange.maxLimitDouble);//Where the Y Axis meets the X axis
    y2.preferredNumberOfMajorTicks = 8;

    y2.majorIntervalLength = CPTDecimalFromDouble(200.0);
    y2.minorTicksPerInterval = 0;
    y2.tickDirection = CPTSignPositive;
    y2.axisLineStyle = axisLineStyle;
    y2.majorTickLineStyle = axisLineStyle;
    y2.title= cFps;
    y2.titleTextStyle = axisTitleTextStyle;
    y2.titleOffset = 30.0;

1 个答案:

答案 0 :(得分:2)

创建NSNumberFormatter,设置positiveSuffix和/或negativeSuffix,并将其设置为轴labelFormatter