2013-05-17 67 views
0

我想在同一散點圖上顯示兩行。我已成功將兩者都放在一張圖表上。一個是綠色的,另一個是紅色的。ios:Coreplot多個數據集具有相同的數據源並重疊?

截至目前,它們似乎是從相同的數據源拉,因此它們重疊。

如果有人可以請告訴我如何訪問graphdata中的其他數據,我將不勝感激!

enter image description here

NSArray* data = [[NSArray alloc] initWithArray:_graphData]; 

    NSDictionary*ds1 = [data objectAtIndex:0]; 
    NSDictionary*ds2 = [data objectAtIndex:1]; 

    CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease]; 
    plot.identifier = [ds1 objectForKey:@"PLOT_IDENTIFIER"]; 

    CPTMutableLineStyle *tyle = [[plot.dataLineStyle mutableCopy] autorelease]; 
    tyle.lineWidth = 19.f; 
    tyle.lineColor = [CPTColor redColor]; 
    tyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:8.0f], nil]; 
    plot.dataLineStyle = tyle; 

    plot.dataSource = self; 
    NSLog(@"%@",plot.dataSource); 

    [self.graph addPlot:plot]; 

    CPTScatterPlot *plot2 = [[[CPTScatterPlot alloc] init] autorelease]; 
    plot2.identifier = [ds2 objectForKey:@"PLOT_IDENTIFIER"]; 
    CPTMutableLineStyle *tyle2 = [[plot2.dataLineStyle mutableCopy] autorelease]; 
    tyle2.lineWidth = 12.f; 
    tyle2.lineColor = [CPTColor greenColor]; 
    tyle2.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:8.0f], nil]; 
    plot2.dataLineStyle = tyle2; 

    plot2.dataSource = self; 

    NSLog(@"%@", plot2.dataSource); 

    [self.graph addPlot:plot2]; 

這裏是數據:

[超級viewDidLoad中];

//This is just so the graph has data without the buttons before them. 
data1 = [NSMutableArray array]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-10.5, 8.5)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-10, 29.2)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-9.5, 39.6)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-9, 48.6)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-8.5, 47.8)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-8, 51.5)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-7.5, 59.5)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-7, 59.4)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-6.5, 83.4)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-6, 78.4)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-5.5, 120.7)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-5, 109.1)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-4.5, 112.4)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-4, 115.3)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-3.5, 111.8)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-3, 108.8)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-2.5, 131.5)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-2, 152.2)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-1.5, 150.2)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-1, 172)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-0.5, 186.4)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(0, 175.1)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(0.5, 164.3)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(1, 165)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(1.5, 159.2)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(2, 146.8)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(2.5, 147.4)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(3, 143.2)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(3.5, 153.8)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(4, 156.7)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(4.5, 159.8)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(5, 144.5)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(5.5, 136.1)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(6, 107.3)]]; 
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(6.5, 78.7)]]; 

//same here 
data2 = [NSMutableArray array]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-10.5, 8.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-10, 29.2)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-9.5, 39.6)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-9, 48.6)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-8.5, 47.8)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-8, 51.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-7.5, 59.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-7, 59.4)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-6.5, 83.4)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-6, 1.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-5.5, 15.6)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-5, 19.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-4.5, 20.2)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-4, 16.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-3.5, 15.1)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-3, 16.6)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-2.5, 19.9)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-2, 19.9)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-1.5, 20)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-1, 23.6)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-0.5, 28.7)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(0, 30.6)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(0.5, 28)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(1, 27.2)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(1.5, 26.7)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(2, 24.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(2.5, 23.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(3, 21.7)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(3.5, 25.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(4, 23.2)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(4.5, 21.2)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(5, 144.5)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(5.5, 136.1)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(6, 107.3)]]; 
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(6.5, 78.7)]]; 



NSDictionary *firstLineDic = [NSDictionary dictionaryWithObjectsAndKeys:@"firstLine", @"PLOT_IDENTIFIER", data1, @"PLOT_DATA", nil]; 
    NSDictionary *secondLineDic = [NSDictionary dictionaryWithObjectsAndKeys:@"secondLine", @"PLOT_IDENTIFIER", data2, @"PLOT_DATA", nil]; 
    NSMutableArray *dictionarydata = [NSMutableArray arrayWithObjects:firstLineDic, secondLineDic, nil]; 
    self.scatterPlot = [[psuScatterSimpleScatterPlot alloc] initWithHostingView:_graphHostingView andData:dictionarydata]; 
    [self.scatterPlot initialisePlot]; 
+0

添加到'data1'和'data2'的對象看起來像包含相同的'CGPoint'值。繪製點的任何原因不會重疊? – bobnoble

+0

數據2確實包含與數據1不同的點。但是,它不是一組完整的數據點,所以我複製並粘貼了第一個表中的缺失數據,因爲我認爲它可能有效?任何其他想法? – pj409

回答

1

檢查您的數據源。我懷疑數據源方法不能正確區分圖。確保每個繪圖都有唯一的identifier,並在數據源中使用它來確定哪個繪圖正在請求數據。

相關問題