您好我正在使用PNChart库(https://github.com/kevinzhow/PNChart),当我尝试将我的数组值设置为绘图时,它会一直崩溃。任何帮助将不胜感激,这是我的代码
[graph setXLabels: paymentAmounts];
// Line Chart No.1
NSArray * data01Array = [[NSArray alloc] initWithArray:balanceWithoutChar];
PNLineChartData *data01 = [PNLineChartData new];
data01.color = PNFreshGreen;
data01.itemCount = graph.xLabels.count;
data01.getData = ^(NSUInteger index) {
CGFloat yValue = [data01Array[index] floatValue];
return [PNLineChartDataItem dataItemWithY:yValue];
};
// Line Chart No.2
NSArray * data02Array = [[NSArray alloc] initWithArray:interestLabels];
PNLineChartData *data02 = [PNLineChartData new];
data02.color = PNTwitterColor;
data02.itemCount = graph.xLabels.count;
data02.getData = ^(NSUInteger index) {
CGFloat yValue = [data02Array[index] floatValue];
return [PNLineChartDataItem dataItemWithY:yValue];
};
graph.chartData = @[data01, data02];
[graph strokeChart];
}
这是我不断收到的错误“NSInvalidArgumentException”,原因:' - [__ NSCFNumber长度]:无法识别的选择器发送到实例0x8d43850“
这是balanceWithoutChar数组的值:
( “458524.43”, “417014.30”, “375469.58”, “333890.23”, “292276.24”, “250627.57”, “208944.19”, “167226.07”, “125473.19”, “83685.52”, “41863.02”, “0.00” )
答案 0 :(得分:0)
graph.xLabels
期待一个NSString。
请记住,在Objective-C中,NSString以@
为前缀。
您可以使用类似
的内容for (int i = 0; i < [dataArray count]; i++) {
NSString *label = [NSString stringWithFormat:@"%d", i];
[balanceWithoutChar insertObject:label atIndex:i];
}
其中dataArray
是原始(浮动?)数据的数组。
通过这种方式,您最终会看到它应该是balanceWithoutChar
,
@[@"458524.43", @"417014.30", @"375469.58", @"333890.23", @"292276.24", @"250627.57", @"208944.19", @"167226.07", @"125473.19", @"83685.52", @"41863.02", @"0.00"]