coreplot - 总是相同的情节

时间:2012-03-20 09:34:17

标签: objective-c ios core-data core-plot

我正在使用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;

}

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

le stupid empty plot

日志 - 最后在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 

1 个答案:

答案 0 :(得分:1)

我认为这是一个简单的错误。图中绘制的线中的每个点都应具有x和y值。您为x和y返回相同的值。您可以通过方法

中的fieldenum值来区分它
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index;

。对于CPTScatterPlotFieldX,fieldenum将为零,对于CPTScatterPlotFieldY,fieldenum将为1.