2012-03-20 5 views
1

im 전나무 시간을 coreplot과 함께 사용하여 지금까지 실행 해 보았습니다. 이제 나는 이상한 문제를 발견했다.coreplot - 항상 동일한 플롯

numberofRecords 
doubleForPlot 

이상 이상) (특히 doubleForPlot를 디버깅 한 :

내가 중요한 기능 또는 coreplot의 개념을 놓친 것을 두려워

=)

메신저 구현 doubleforplot이 실제로 주어진 인덱스에 대해 올바른 double을 반환하는지 100 % 확신해야합니다.

그러나 : 표시된 플롯은 항상입니다. 나는 질문의 하단에있는 스크린 샷을 얻는다.

내가 시도 : 디버깅 doubleForPlot를 - 그것은 다른 데이터 내가 상수 라인, 결과보고 기대, 항상 같은 수를 반환하려 권리 수를 반환 : 빈 플롯합니다. 다른 데이터 나는 다른 값 (상수가 아님)을 반환하려고 시도했지만 그 다음에 표시된 스크린 샷을 다시 볼 수 있습니다.

IBAction를 - 데이터 inizalisation를 호출하고

-(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; 
} 

} 

보기 만들기 graphview에게 빌드 - 적당한 크기

-(CPTGraphHostingView *)buildGraphView{ 

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

return view; 
} 
와 호스팅 뷰를 초기화한다 : 여기

내 코드입니다

데이터 초기화은 - 인덱스

-(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에 적합한 더블을 반환 - - 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에게 보여 명중 될 때 호출되는 항목

의 권리 금액을 반환
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{  
return [dataHandler getDayNumber:[NSDate date]].intValue; 

} 

스크린 샷 - 아무리 입력 어떤 데이터가 표시되지 않습니다 플롯

le stupid empty plot

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 

답변

1

나는 그것이 단순한 오류라고 생각합니다. 그래프에 그려지는 선의 모든 점에는 x와 y 값이 있어야합니다. x와 y에 대해 같은 값을 반환합니다. 방법의 계측 값으로 구분할 수 있습니다.

-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index; 

필드시는 CPTScatterPlotFieldX에 대해서는 0이고, CPTScatterPlotFieldY에 대해서는 1이다.

+0

안녕하세요 - 감사합니다. 이것은 직선 x = y를 나타내는 이유를 설명합니다. 나는 그것을 변경했다. (문제의 새 코드를 보자.)하지만 이제 나는 빈 줄거리를 얻는다. 그래서 아직까지는 안됨) –

+0

그래프의 범위를 올바르게 설정 했습니까? – Neo

+0

aaand - 그 사람은 =) –

관련 문제