Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
- return 50;
- }
- -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
- double val = index/10.0;
- //NSLog(@"index = %d, val = %f, val^2 = %f", index, val, val*val);
- if (fieldEnum == CPTScatterPlotFieldX) {
- return [NSNumber numberWithDouble:val];
- } else {
- if (plot.identifier == @"X Squared Plot") {
- return [NSNumber numberWithDouble:exp(val)];
- } else {
- return [NSNumber numberWithDouble:val*val];
- }
- }
- }
- #pragma mark - View lifecycle
- -(void)setupGraphWithXRangeLocation:(float)xLocation XLength:(float)xLength YRangeLocation:(float)yLocation YLength:(float)yLength {
- graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
- CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
- hostingView.hostedGraph = graph;
- graph.paddingLeft = 20.0;
- graph.paddingTop = 20.0;
- graph.paddingRight = 20.0;
- graph.paddingBottom = 20.0;
- CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
- plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xLocation) length:CPTDecimalFromFloat(xLength)];
- plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yLocation) length:CPTDecimalFromFloat(yLength)];
- //plotSpace.yScaleType = CPTScaleTypeLinear;
- CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
- lineStyle.lineColor = [CPTColor blackColor];
- lineStyle.lineWidth = 2.0f;
- CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
- CPTXYAxis *xAxis = axisSet.xAxis;
- xAxis.majorIntervalLength = CPTDecimalFromInt(5);
- xAxis.minorTicksPerInterval = 4;
- xAxis.majorTickLineStyle = lineStyle;
- xAxis.minorTickLineStyle = lineStyle;
- xAxis.axisLineStyle = lineStyle;
- xAxis.minorTickLength = 5.0f;
- xAxis.majorTickLength = 7.0f;
- xAxis.axisTitle.offset = 3.0f;
- CPTXYAxis *yAxis = axisSet.yAxis;
- yAxis.majorIntervalLength = CPTDecimalFromInt(5);
- yAxis.minorTicksPerInterval = 4;
- yAxis.majorTickLineStyle = lineStyle;
- yAxis.minorTickLineStyle = lineStyle;
- yAxis.axisLineStyle = lineStyle;
- yAxis.minorTickLength = 5.0f;
- yAxis.majorTickLength = 7.0f;
- yAxis.axisTitle.offset = 3.0f;
- CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] init] autorelease];
- xSquaredPlot.identifier = @"X Squared Plot";
- CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
- dataLineStyle.lineColor = [CPTColor redColor];
- dataLineStyle.lineWidth = 1.0f;
- xSquaredPlot.dataLineStyle = dataLineStyle;
- xSquaredPlot.dataSource = self;
- [graph addPlot:xSquaredPlot];
- CPTScatterPlot *xInversePlot = [[[CPTScatterPlot alloc] init] autorelease];
- xInversePlot.identifier = @"X Inverse Plot";
- CPTMutableLineStyle *dataLineStyle2 = [CPTMutableLineStyle lineStyle];
- dataLineStyle2.lineColor = [CPTColor blueColor];
- dataLineStyle2.lineWidth = 1.0f;
- xInversePlot.dataLineStyle = dataLineStyle2;
- xInversePlot.dataSource = self;
- [graph addPlot:xInversePlot];
- plotSpace.xScaleType = CPTScaleTypeLinear;
- plotSpace.yScaleType = CPTScaleTypeLog;
- }
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self setupGraphWithXRangeLocation:-1
- XLength:6
- YRangeLocation:-1
- YLength:25];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement