首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心情节-总是相同的情节

核心情节-总是相同的情节
EN

Stack Overflow用户
提问于 2012-03-20 09:34:16
回答 1查看 364关注 0票数 1

我工作的核心计划的第一时间-和它的启动和运行到目前为止。现在我偶然发现了一个奇怪的问题。

我担心我错过了一个重要的函数或核心图=)

的概念

我已执行:

代码语言:javascript
复制
numberofRecords
doubleForPlot

并且一次又一次地调试(特别是doubleForPlot),并且100%确信doubleforplot实际上返回了给定索引的正确的double。

但是:显示的情节是总是一样。我得到了一条线(问题底部的截图)。

我尝试了:调试 doubleForPlot -它返回正确的数字-不同的数据我尝试返回总是相同的数字,期望看到一个常数行,结果:一个空的情节。不同的数据,,我尝试返回一些其他的值(不是常量),但是我再次得到了显示的屏幕截图。

这是我的代码:

IBAction -调用数据初始化并构建图形视图。

代码语言:javascript
复制
-(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;
}

}

创建视图-初始化大小合适的宿主视图

代码语言:javascript
复制
-(CPTGraphHostingView *)buildGraphView{

CPTGraphHostingView *view = [[CPTGraphHostingView alloc]initWithFrame:CGRectMake(0, 0, 312, 220)];
[view setBackgroundColor:[self grayColor]];

return view;
}

数据初始化-在按下IBAction以显示图形时调用

代码语言:javascript
复制
-(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 -返回索引的右双倍

代码语言:javascript
复制
-(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 -返回正确的条目数量

代码语言:javascript
复制
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{    
return [dataHandler getDayNumber:[NSDate date]].intValue;

}

屏幕截图-无论输入什么数据都显示的情节

log --这个日志是在doubleforplot方法中创建的,在最后证明返回了正确的结果:

代码语言:javascript
复制
NSLog(@"\n Record for Day: %@ \n IndexForPlot: %d \n Value: %.2f \n",date,index,total);

退出:

代码语言:javascript
复制
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 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-20 09:55:07

我认为这是一个简单的错误。图中画的每一点都应该有x和y值。对x和y返回相同的值,可以通过方法中的fieldenum值来区分它。

代码语言:javascript
复制
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index;

。CPTScatterPlotFieldX场均为0,CPTScatterPlotFieldY为1。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9784259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档