1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| -(void) plotData{ if ([dataSourceLinePlot.identifier isEqual:@"Green Plot"]) { NSString *xp1 = [NSString stringWithFormat:@"%d",1]; NSString *yp1 = [NSString stringWithFormat:@"%d",10]; NSMutableDictionary *point1 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp1, @"x", yp1, @"y", nil]; [dataForPlot1 insertObject:point1 atIndex:0]; NSString *xp2 = [NSString stringWithFormat:@"%d",10]; NSString *yp2 = [NSString stringWithFormat:@"%d",25]; NSMutableDictionary *point2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp2, @"x", yp2, @"y", nil]; [dataForPlot1 insertObject:point2 atIndex:1]; NSString *xp3 = [NSString stringWithFormat:@"%d",30]; NSString *yp3 = [NSString stringWithFormat:@"%d",15]; NSMutableDictionary *point3 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp3, @"x", yp3, @"y", nil]; [dataForPlot1 insertObject:point3 atIndex:2]; NSString *xp4 = [NSString stringWithFormat:@"%d",50]; NSString *yp4 = [NSString stringWithFormat:@"%d",80]; NSMutableDictionary *point4 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp4, @"x", yp4, @"y", nil]; [dataForPlot1 insertObject:point4 atIndex:3]; NSString *xp5 = [NSString stringWithFormat:@"%d",70]; NSString *yp5 = [NSString stringWithFormat:@"%d",60]; NSMutableDictionary *point5 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp5, @"x", yp5, @"y", nil]; [dataForPlot1 insertObject:point5 atIndex:4]; NSString *xp6 = [NSString stringWithFormat:@"%d",90]; NSString *yp6 = [NSString stringWithFormat:@"%d",100]; NSMutableDictionary *point6 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp6, @"x", yp6, @"y", nil]; [dataForPlot1 insertObject:point6 atIndex:5]; NSString *xp7 = [NSString stringWithFormat:@"%d",110]; NSString *yp7 = [NSString stringWithFormat:@"%d",70]; NSMutableDictionary *point7 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp7, @"x", yp7, @"y", nil]; [dataForPlot1 insertObject:point7 atIndex:6]; NSString *xp8 = [NSString stringWithFormat:@"%d",130]; NSString *yp8 = [NSString stringWithFormat:@"%d",80]; NSMutableDictionary *point8 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp8, @"x", yp8, @"y", nil]; [dataForPlot1 insertObject:point8 atIndex:7]; NSString *xp9 = [NSString stringWithFormat:@"%d",200]; NSString *yp9 = [NSString stringWithFormat:@"%d",135]; NSMutableDictionary *point9 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:xp9, @"x", yp9, @"y", nil]; [dataForPlot1 insertObject:point9 atIndex:8]; } }
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{ return [dataForPlot1 count]; }
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{ NSString *key = (fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y"); NSNumber *num; if ( [(NSString *)plot.identifier isEqualToString:@"Green Plot"] ) { num = [[dataForPlot1 objectAtIndex:index] valueForKey:key]; if ( fieldEnum == CPTScatterPlotFieldX ) { num = [NSNumber numberWithDouble:[num doubleValue] - r]; } } CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeInAnimation.duration = 1.0f; fadeInAnimation.removedOnCompletion = NO; fadeInAnimation.fillMode = kCAFillModeForwards; fadeInAnimation.toValue = [NSNumber numberWithFloat:2.0]; [dataSourceLinePlot addAnimation:fadeInAnimation forKey:@"animateOpacity"]; return num; }
|