Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 核心图和显示y标签_Ios_Core Plot - Fatal编程技术网

Ios 核心图和显示y标签

Ios 核心图和显示y标签,ios,core-plot,Ios,Core Plot,我在用iOS和Core Plot正确显示y轴标签时遇到了一些问题 我将向您展示我目前拥有的两个不同场景,希望有人能帮助我使其中一个正常工作 好的,那么第一个场景: 守则: // Configure y-axis CPTAxis *y = axisSet.yAxis; y.axisLineStyle = axisLineStyle; y.majorGridLineStyle = customGridStyle; y.labelingPolicy = CPTAxisLabelingPolicyAut

我在用iOS和Core Plot正确显示y轴标签时遇到了一些问题

我将向您展示我目前拥有的两个不同场景,希望有人能帮助我使其中一个正常工作

好的,那么第一个场景: 守则:

// Configure y-axis
CPTAxis *y = axisSet.yAxis;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = customGridStyle;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.labelTextStyle = axisTextStyle;
y.majorTickLineStyle = axisLineStyle;
y.majorTickLength = 0.0f;
y.minorTickLength = 0.0f;
y.tickDirection = CPTSignNegative;
NSInteger majorIncrement = [self findStep:(maxValue - minValue)/7];
CGFloat yMax = [self findMaximumValue:maxValue];
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];

int maxLocation = 0;

for (NSInteger j = 0; j <= yMax + majorIncrement; j += majorIncrement) {
    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", j] textStyle:y.labelTextStyle];
    NSDecimal location = CPTDecimalFromInteger(j);
    label.tickLocation = location;
    label.offset = 125;

    if (label) {
        [yLabels addObject:label];
    }

    [yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
    if (maxLocation < [[NSDecimalNumber decimalNumberWithDecimal:location] intValue]) {
        maxLocation = [[NSDecimalNumber decimalNumberWithDecimal:location] intValue];
    }
}

y.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(maxLocation)];
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
//配置y轴
CPTAxis*y=axisSet.yAxis;
y、 axisLineStyle=axisLineStyle;
y、 majorGridLineStyle=customGridStyle;
y、 labelingPolicy=CPTAxisLabelingPolicyAutomatic;
y、 labelTextStyle=axisTextStyle;
y、 majorTickLineStyle=axisLineStyle;
y、 majorTickLength=0.0f;
y、 minorTickLength=0.0f;
y、 tickDirection=CPTSignNegative;
NSInteger-majorIncrement=[self-findStep:(maxValue-minValue)/7];
CGFloat yMax=[self-findMaximumValue:maxValue];
NSMutableSet*yLabels=[NSMutableSet];
NSMutableSet*yMajorLocations=[NSMutableSet];
int maxLocation=0;

对于使用
cptaxislabelingpolicyne
labeling策略的(NSInteger j=0;j),您完全可以控制勾号的位置和标签。由您决定制作多少勾号和标签以及将它们放置在何处


如果您只想更改轴上的数字格式,请保持
cptaxislabelingpolicy自动
标记策略(或除
cptaxislabelingpolicy以外的任何其他策略
),删除创建记号位置和标签的代码,并更改
labelFormatter
。您可以使用任何
NSFormatter
。创建
NSNumberFormatter
,将其配置为显示所需的数字格式,并将其设置为
labelFormatter
属性。

谢谢,Eric!我真的想创建标签使用None策略,我可以更好地控制步骤等,但现在我使用的解决方案是格式化labelFormatter,直到我让另一部分工作得更好…谢谢!
// Configure y-axis
CPTAxis *y = axisSet.yAxis;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = customGridStyle;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = axisTextStyle;
y.majorTickLineStyle = axisLineStyle;
y.majorTickLength = 0.0f;
y.minorTickLength = 0.0f;
y.tickDirection = CPTSignPositive;
NSInteger majorIncrement = [self findStep:(maxValue - minValue)/7];
CGFloat yMax = [self findMaximumValue:maxValue];
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];

int maxLocation = 0;

for (NSInteger j = 0; j <= yMax + majorIncrement; j += majorIncrement) {
    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", j] textStyle:y.labelTextStyle];
    NSDecimal location = CPTDecimalFromInteger(j);
    label.tickLocation = location;
    label.offset = -25;

    if (label) {
        [yLabels addObject:label];
    }

    [yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
    if (maxLocation < [[NSDecimalNumber decimalNumberWithDecimal:location] intValue]) {
        maxLocation = [[NSDecimalNumber decimalNumberWithDecimal:location] intValue];
    }
}

y.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(maxLocation)];
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
x.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(maxLocation)];