簡體   English   中英

coreplot 2圖中的圖

[英]coreplot 2 plots in graph

我目前正在使用coreplot為應用程序創建圖形,並且有一個我無法解釋的問題。

我讀了(它沒有幫助): 核心圖,無法繪制兩個圖

問題:為什么只顯示第二個添加的圖? 如果我更改了將它們添加到hostView的順序,則僅顯示我添加的最后一個。 請參見下面的代碼和屏幕截圖。

該圖將包含2個不同的圖

PROBLEM:
- both plots show perfectly if added alone.
- if i add both plots, only the second (last) one added gets displayed.
- to assure you that both are well on their own i added screenshots on the bottom.

首先畫一條0線

identifier : @"nullLine"
name: nullPlot

第二個圖我已存儲的數據散點圖

identifier : @"balanceChart"
name: plot

這是我的一些代碼:

    CPTGraphHostingView *host = [self buildGraphView];   //returns a viewwithframe
    [view addSubview:host];

    graph = [[CPTXYGraph alloc ]initWithFrame:host.frame];
    host.hostedGraph = graph;

    CPTScatterPlot *plot = [[CPTScatterPlot alloc]init ];
    plot.dataSource = self;
    [plot setIdentifier:@"balanceChart"];

    // Setup plot space
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.allowsUserInteraction = YES;
    plotSpace.xRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(20.0)];
    plotSpace.yRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-200.0) length:CPTDecimalFromFloat(400.0)];

    CPTScatterPlot *nullPlot = [[CPTScatterPlot alloc]init ];
    nullPlot.dataSource = self;
    [nullPlot setIdentifier:@"nullLine"];
    [nullPlot setPlotSpace:plotSpace];
    [plot setPlotSpace:plotSpace];


    [graph addPlot:nullPlot];
    [graph addPlot:plot];

和我的doubleForPlot函數:

注意:我只添加此功能以完成操作-絕對會100%返回兩個圖的正確值!

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

// NULL CHART
if ([(NSString *)plot.identifier isEqualToString:@"nullLine"]) {
    if (fieldEnum == CPTScatterPlotFieldX) {
        NSLog(@"Plot: %@,fieldEnum: %d, index: %d",plot,fieldEnum,index);
        return index+1;
    }
    if (fieldEnum == CPTScatterPlotFieldY) {
        NSLog(@"Plot: %@,fieldEnum: %d, index: %d",plot,fieldEnum,index);
        double zero = 0;
        return zero;
    }
}


// BALANCE CHART
if ([(NSString *)plot.identifier isEqualToString:@"balanceChart"]) {

    if (fieldEnum == CPTScatterPlotFieldX) {

        NSLog(@"Axis: %d and Value: %d",fieldEnum, index+1);
        return (double)(index+1);
    }

    if (fieldEnum == CPTScatterPlotFieldY) {

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


return 0;
}

這是numberOfRecordsForPlot方法:

注意兩個圖都有相同數量的記錄。 這也返回正確的數字。

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{    
return [dataHandler getDayNumber:[NSDate date]].intValue;

}

balanceChart

nullLine

旁注請介意圖的格式;-)

我在一個測試應用程序中嘗試了您的代碼,並且效果很好-都顯示了兩個圖。 您的代碼中肯定還有其他情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM