gpt4 book ai didi

ios - 在核心图中动态更改 Y 轴标签和线条

转载 作者:行者123 更新时间:2023-11-29 02:41:48 26 4
gpt4 key购买 nike

我想动态改变 Y 轴。我有最大和最小文本字段。当我更改最大或最小字段时,图表将更改 Y 轴。

我试过像下面这样但只有两条线来了。请检查以下代码。

这是配置Y轴的方法。

CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.majorTickLength = 0.0;

NSMutableSet *yLabels = [NSMutableSet setWithCapacity:4];
NSMutableSet *yLocations = [NSMutableSet setWithCapacity:4];

NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];

CGFloat max_value = [[preferences valueForKey:MAX_KEY] integerValue];
CGFloat min_value = [[preferences valueForKey:MIN_KEY] integerValue];

NSLog(@"max_value%f",max_value);

NSInteger range = ((max_value-min_value)*10)/100;

NSLog(@"range%d",range);
newmaxValue = (max_value-min_value) - range;
newMinValue = min_value - range;

yAxisLabels = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%.f",newMinValue], [NSString stringWithFormat:@"%.f",newMinValue+20],[NSString stringWithFormat:@"%.f",newmaxValue-20],[NSString stringWithFormat:@"%.f",newmaxValue], nil];

yAxiscustomTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:newMinValue], [NSDecimalNumber numberWithInt:newMinValue+20], [NSDecimalNumber numberWithInt:newmaxValue-20], [NSDecimalNumber numberWithInt:newmaxValue],nil];


NSNumberFormatter * nFormatter = [[NSNumberFormatter alloc] init];
[nFormatter setNumberStyle:NSNumberFormatterDecimalStyle];

for ( NSUInteger i = 0; i < [yAxisLabels count]; i++ ) {

CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%@",[yAxisLabels objectAtIndex:i]] textStyle:axisTextStyle];
label.tickLocation = CPTDecimalFromInteger([[yAxiscustomTickLocations objectAtIndex:i] integerValue]);
//label.offset = y.labelOffset + y.majorTickLength;
NSLog(@"%d",[[yAxiscustomTickLocations objectAtIndex:i] integerValue]);

label.offset = y.majorTickLength+2;
if (label) {
[yLabels addObject:label];
[yLocations addObject:[NSString stringWithFormat:@"%d",[[yAxiscustomTickLocations objectAtIndex:i] integerValue]]];
}
label = nil;
}

NSLog(@"newmaxValue%f",newmaxValue);
NSLog(@"newMinValue%f",newMinValue);

y.axisLabels = yLabels;
y.majorTickLocations = [NSSet setWithArray:yAxiscustomTickLocations];
y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat((NSInteger)newMinValue) length:CPTDecimalFromFloat((NSInteger)newmaxValue)];
y.labelFormatter = nFormatter;

我也是这样设置范围的

[self getCoreplotSpace].xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0.0f) length:CPTDecimalFromUnsignedInteger(1800.0f)];

[self getCoreplotSpace].yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger((NSInteger)newMinValue) length:CPTDecimalFromInteger((NSInteger)newmaxValue)];

编辑::

日志输出

  newmaxValue225.000000
newMinValue-75.000000
yAxisLabels(
"-75",
"-55",
205,
225
)
yAxiscustomTickLocations(
"-75",
"-55",
205,
225
)

你们能帮帮我吗...

谢谢

最佳答案

您的问题在您指定 y 轴可见范围的末尾:

y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat((NSInteger)newMinValue) length:CPTDecimalFromFloat((NSInteger)newmaxValue)];

长度应该是范围,而不是newmaxValue:

y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat((NSInteger)newMinValue) length:CPTDecimalFromFloat((NSInteger)(newmaxValue-newminValue))];

关于ios - 在核心图中动态更改 Y 轴标签和线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25679484/

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