0

i am trying to display two lines on the same scatter plot. I've successfully put both on one chart. One is green, the other, red.

As of right now, they appear to be pulling from the same data source, thus they are overlapping.

If someone could please tell me how to access the other data in the graphdata, i would greatly appreciate it!

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

Here is the data:

[super 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];
2
  • The objects added to data1 and data2 look like they contain the same set of CGPoint values. Any reason the points plotted would not overlap?
    – bobnoble
    Commented May 17, 2013 at 9:40
  • data 2 does contain different points than data 1. However, it was not a full set of data points so I copy and pasted the missing data from the first table because I thought it may work? Any other ideas?
    – pj409
    Commented May 17, 2013 at 10:53

1 Answer 1

1

Check your datasource. I suspect the datasource methods don't distinguish the plots correctly. Make sure each plot has a unique identifier and use that in the datasource to determine which plot is requesting data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.