0

我试图在同一个散点图上显示两条线。我已经成功地将两者都放在了一张图表上。一个是绿色的,另一个是红色的。

截至目前,它们似乎是从同一个数据源中提取的,因此它们是重叠的。

如果有人能告诉我如何访问graphdata中的其他数据,我将不胜感激!

在此处输入图像描述

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

这是数据:

[超级视图DidLoad];

//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];
4

1 回答 1

1

检查您的数据源。我怀疑数据源方法不能正确区分这些图。确保每个图都有一个唯一的identifier并在数据源中使用它来确定哪个图正在请求数据。

于 2013-05-17T23:03:26.687 回答