我目前正在使用coreplot为应用程序创建图形,并且有一个我无法解释的问题。

我读了(它没有帮助):
core-plot, unable to plot two graphs

问题:为什么只显示第二个添加的图?如果我更改了将它们添加到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;

}



旁注不介意地块的格式;-)

最佳答案

我在一个测试应用程序中尝试了您的代码,并且效果很好-都显示了两个图。您的代码中肯定还有其他情况。

关于iphone - coreplot 2图中的图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9819761/

10-11 22:55
查看更多