1

I have been working on this all day and still haven't a clue. I have made two datasets and put them into a dictionary that I then use as the datasource for my plot. Everything should be working but It still only displays one chart.

Interestingly enough if I change the order of the PLOT_IDENTIFIER, that plot's data is the one that is displayed, not the other.

Here is where I make the data and dictionary:

- (void)viewDidLoad
{
    [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(-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)]];

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

Here's where I make the chart:

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


    for (NSDictionary *dic in data) {
        CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease];
        plot.dataSource = self;
        plot.identifier = [dic objectForKey:@"PLOT_IDENTIFIER"];
        plot.plotSymbol = plotSymbol;
        plot.dataLineStyle = lineStyle;

        [self.graph addPlot:plot];

        }



}

// Delegate method that returns the number of points on the plot




-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
    NSArray* data = [[NSArray alloc] initWithArray:_graphData];

    for (NSDictionary *dic in data) {
        NSString *identity = [dic objectForKey:@"PLOT_IDENTIFIER"];

        if([plot.identifier isEqual:identity]){
            NSArray *arr = [dic objectForKey:@"PLOT_DATA"];
            return [arr count];
        }
    }
    return 0;
}


// Delegate method that returns a single X or Y value for a given plot.
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
    if ([plot.identifier isEqual:@"firstLine"] || [plot.identifier isEqual:@"secondLine"])
    {
        NSDictionary*jay = [_graphData objectAtIndex:0];

        NSArray *jay2 = [jay objectForKey:@"PLOT_DATA"];
        NSValue *value = [jay2 objectAtIndex:index];
        CGPoint point = [value CGPointValue];

        // FieldEnum determines if we return an X or Y value.
        if ( fieldEnum == CPTScatterPlotFieldX )
        {
            return [NSNumber numberWithFloat:point.x];
        }
        else    // Y-Axis
        {
            return [NSNumber numberWithFloat:point.y];
        }
    }

    return [NSNumber numberWithFloat:0];

}

1 Answer 1

1

In the datasource method, you specified the first object of "_graphData" array. This is the pblm. Change the code as below:

 -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:  (NSUInteger)index
 {

   if ([plot.identifier isEqual:@"firstLine"])
   {
       NSDictionary *firstDataSet = [_graphData objectAtIndex:0];
       //Code for processing the points here

   }
   else if([plot.identifier isEqual:@"secondLine"])
   {
        NSDictionary *secondDataSet = [_graphData objectAtIndex:1];
        //Code for processing the points here
   }
}

Hope it helps...

0

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.