首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图中的核心图2

图中的核心图2
EN

Stack Overflow用户
提问于 2012-03-22 09:48:28
回答 1查看 1.1K关注 0票数 2

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

我读到(但没什么用):core-plot, unable to plot two graphs

问题:为什么只显示第二个添加的情节?如果更改将它们添加到hostView中的顺序,则只显示我添加的最后一个顺序。请参阅下面的代码和屏幕截图.

这张图将包含两个不同的情节

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

代码语言:javascript
复制
identifier : @"nullLine"
name: nullPlot

第二绘图我存储的数据散点图

代码语言:javascript
复制
identifier : @"balanceChart"
name: plot

以下是我的一些代码:

代码语言:javascript
复制
    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%地返回两个图的正确值!

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

注意到两个地块都有相同的记录量。这也会返回正确的数字。

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

}

sidenote请不要介意情节的格式;-)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-23 01:28:31

我在一个测试应用程序中尝试了你的代码,结果很好--两个情节都出现了。在您的代码中一定有其他的事情发生。

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

https://stackoverflow.com/questions/9819761

复制
相关文章

相似问题

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