我工作的核心计划的第一时间-和它的启动和运行到目前为止。现在我偶然发现了一个奇怪的问题。
我担心我错过了一个重要的函数或核心图=)
的概念
我已执行:
numberofRecords
doubleForPlot并且一次又一次地调试(特别是doubleForPlot),并且100%确信doubleforplot实际上返回了给定索引的正确的double。
但是:显示的情节是总是一样。我得到了一条线(问题底部的截图)。
我尝试了:调试 doubleForPlot -它返回正确的数字-不同的数据我尝试返回总是相同的数字,期望看到一个常数行,结果:一个空的情节。不同的数据,,我尝试返回一些其他的值(不是常量),但是我再次得到了显示的屏幕截图。
这是我的代码:
IBAction -调用数据初始化并构建图形视图。
-(IBAction)displayDayBalanceGraph:(id)sender{
if (hasSubView) {
//[[expenseTable subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
[self updateView];
NSLog(@"%@",expenseTable.subviews);
}
else{
[self initializeMonthArray];
CPTGraphHostingView *host = [self buildGraphView];
[expenseTable addSubview:host];
graph = [[CPTXYGraph alloc ]initWithFrame:host.frame];
[graph setDelegate:self];
// CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
// [graph applyTheme:theme];
host.hostedGraph = graph;
CPTScatterPlot *plot = [[CPTScatterPlot alloc]init ];
plot.dataSource = self;
[plot setIdentifier:@"balanceChart"];
[plot setTitle:@"Balance History"];
[graph addPlot:plot];
hasSubView = !hasSubView;
}
}创建视图-初始化大小合适的宿主视图
-(CPTGraphHostingView *)buildGraphView{
CPTGraphHostingView *view = [[CPTGraphHostingView alloc]initWithFrame:CGRectMake(0, 0, 312, 220)];
[view setBackgroundColor:[self grayColor]];
return view;
}数据初始化-在按下IBAction以显示图形时调用
-(void)initializeMonthArray{
[dataHandler updateData];
if (!allMonthExpenses) {
allMonthExpenses = [[NSMutableArray alloc]initWithCapacity:31];
}
for (NSMutableArray *temp in allMonthExpenses) {
[temp removeAllObjects];
}
[allMonthExpenses removeAllObjects];
for (int j = 0; j < 31; j++) { //fill with 31 empty mutuable arrays
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
[allMonthExpenses addObject:tempArray];
}
for (Expense *exp in dataHandler.allMonthExpenses) {
if (exp.expenseType.boolValue == 0) {
[[allMonthExpenses objectAtIndex:(exp.day.intValue-1)]addObject:exp];
}
}
}doubleForPlot -返回索引的右双倍
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{
if (fieldEnum == 0) {
NSLog(@"Axis: %d and Value: %d",fieldEnum, index+1);
return (double)(index+1);
}
if (fieldEnum == 1) {
int dayInt = [dataHandler getDayNumber:[NSDate date]].intValue;
double total = 0;
for (Expense *exp in [allMonthExpenses objectAtIndex:index]) {
total = total + exp.value.doubleValue;
}
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:(-(dayInt-(int)index-1)*(60*60*24))];
double budgetValue = [dataHandler getSpecificBudgetForDate:[NSDate dateWithTimeIntervalSinceNow:(-(dayInt-(int)index-1)*(60*60*24))] ];
total = budgetValue+total;
NSLog(@"\n Axis:%d \n Record for Day: %@ \n IndexForPlot: %d \n Value: %.2f \n",fieldEnum, date,index,total);
return total;
}
else
return 0;
}numberOfRecords -返回正确的条目数量
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{
return [dataHandler getDayNumber:[NSDate date]].intValue;
}屏幕截图-无论输入什么数据都显示的情节

log --这个日志是在doubleforplot方法中创建的,在最后证明返回了正确的结果:
NSLog(@"\n Record for Day: %@ \n IndexForPlot: %d \n Value: %.2f \n",date,index,total);退出:
2012-03-20 10:29:55.834 DailyBudget[9493:fb03]
Record for Day: 2012-03-01 09:29:55 +0000
IndexForPlot: 0
Value: 34.35
2012-03-20 10:29:55.841 DailyBudget[9493:fb03]
Record for Day: 2012-03-02 09:29:55 +0000
IndexForPlot: 1
Value: 8.35
2012-03-20 10:29:55.848 DailyBudget[9493:fb03]
Record for Day: 2012-03-03 09:29:55 +0000
IndexForPlot: 2
Value: 35.83
2012-03-20 10:29:55.856 DailyBudget[9493:fb03]
Record for Day: 2012-03-04 09:29:55 +0000
IndexForPlot: 3
Value: -14.89
2012-03-20 10:29:55.863 DailyBudget[9493:fb03]
Record for Day: 2012-03-05 09:29:55 +0000
IndexForPlot: 4
Value: 36.56
2012-03-20 10:29:55.869 DailyBudget[9493:fb03]
Record for Day: 2012-03-06 09:29:55 +0000
IndexForPlot: 5
Value: 8.96
.... sparing you a lot of other log except the last.
2012-03-20 10:29:55.980 DailyBudget[9493:fb03]
Record for Day: 2012-03-20 09:29:55 +0000
IndexForPlot: 19
Value: 14.33 发布于 2012-03-20 09:55:07
我认为这是一个简单的错误。图中画的每一点都应该有x和y值。对x和y返回相同的值,可以通过方法中的fieldenum值来区分它。
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index;。CPTScatterPlotFieldX场均为0,CPTScatterPlotFieldY为1。
https://stackoverflow.com/questions/9784259
复制相似问题