gpt4 book ai didi

ios - 核心图和显示 y 标签

转载 作者:行者123 更新时间:2023-11-28 22:31:57 24 4
gpt4 key购买 nike

我在使用 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;

现在这段代码在一定程度上起作用了……请看下面的截图: Core Plot Core Plot 2

这里我想更改的部分是小数点...我想将位置小数点更改为现在显示 .0...

  1. 场景(我非常想修复的那个)为了省去阅读下面代码的麻烦,我可以指出这里最大的变化是

    y.labelingPolicy = CPTAxisLabelingPolicyNone;

代码:

// 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)];

情节如下:

Core Plot 3 Core Plot 4 Core Plot 5

现在这里缺少很多 y 轴......

如有任何帮助,我们将不胜感激!

最佳答案

使用 CPTAxisLabelingPolicyNone 标签策略,您可以完全控制刻度位置和标签。由您决定制作多少刻度和标签以及将它们放在哪里。

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

关于ios - 核心图和显示 y 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17172788/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com