即时与coreplot工作的第一次 - 并得到它运行到目前为止。现在我偶然发现了一个奇怪的问题。coreplot - 总是同样的阴谋
我担心我错过了一个重要的功能或coreplot的概念=)
即时实现:
numberofRecords
doubleForPlot
并已调试(尤其doubleForPlot)反复并且100%肯定doubleforplot实际上会返回给定索引的正确double。
但是:显示的图是总是一样。我得到一条线(问题底部的屏幕截图)。
我想: 调试 doubleForPlot - 它返回正确的号码 不同的数据我尝试总是返回相同的号码,希望看到一个不断线,结果:一个空的阴谋。 不同的数据我试着返回一些其他的值(不是常量),但后来我得到了所示的截图重复一遍。
这里是我的代码:
IBAction为 - 调用数据inizalisation并建立graphview
-(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
嗨,谢谢!这解释了为什么它会显示一条直线x = y。我改变了它(看到新的代码) - 但现在我得到一个空的阴谋(见截图)。所以还没有完成;) – 2012-03-20 10:04:56
您是否正确设置图形的范围? – Neo 2012-03-20 10:15:38
aaand - 那个人做了它=) – 2012-03-20 11:33:53