core plot 使用方法

p.p1 {margin: 0.0px 0.0px 12.0px 0.0px; font: 11.0px Menlo} p.p2 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo} p.p3 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #00830e} p.p4 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #3f2080} p.p5 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #ce3124} p.p6 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #518187} p.p7 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px} p.p8 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #33595d} p.p9 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #b931a1} p.p10 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px 'Trebuchet MS'; color: #00830e} p.p11 {margin: 0.0px 0.0px 11.0px 0.0px; font: 11.0px Menlo; color: #7140a8} span.s1 {color: #b931a1} span.s2 {color: #518187} span.s3 {color: #000000} span.s4 {color: #7140a8} span.s5 {color: #33595d} span.s6 {color: #3130d6} span.s7 {font: 11.0px 'Trebuchet MS'} span.s8 {color: #ce3124} span.s9 {color: #00830e} span.s10 {font: 11.0px 'Trebuchet MS'; color: #00830e} span.s11 {color: #3f2080} span.s12 {font: 11.0px Menlo} span.s13 {color: #77492d}

- (void)constructScatterPlot

{

// Create graph from theme

graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];

CPTheme *theme = [CPTheme themeNamed: @"Dark Gradients"];

[graph applyTheme:theme];

scatterPlotView.hostedGraph = graph;

graph.paddingLeft = 10.0;

graph.paddingTop = 10.0;

graph.paddingRight = 10.0;

graph.paddingBottom = 10.0;

// Setup plot space

CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;

plotSpace.allowsUserInteraction = YES;

//设置x y

plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0) length:CPDecimalFromFloat(2.0)];

plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0) length:CPDecimalFromFloat(3.0)];

// Axes

CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;

CPXYAxis *x = axisSet.xAxis;

x.majorIntervalLength = CPDecimalFromString(@"2");//设置坐标轴的单位长度

x.orthogonalCoordinateDecimal = CPDecimalFromString(@"2");//设置坐标系的交叉位置

x.minorTicksPerInterval = 2;

NSArray *exclusionRanges = [NSArray arrayWithObjects:

[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.99) length:CPDecimalFromFloat(0.02)],

[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.99) length:CPDecimalFromFloat(0.02)],

[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(2.99) length:CPDecimalFromFloat(0.02)],

nil];

x.labelExclusionRanges = exclusionRanges;

CPXYAxis *y = axisSet.yAxis;

y.majorIntervalLength = CPDecimalFromString(@"0.5");

y.minorTicksPerInterval = 5;

y.orthogonalCoordinateDecimal = CPDecimalFromString(@"2");

exclusionRanges = [NSArray arrayWithObjects:

[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.99) length:CPDecimalFromFloat(0.02)],

[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.99) length:CPDecimalFromFloat(0.02)],

[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(3.99) length:CPDecimalFromFloat(0.02)],

nil];

y.labelExclusionRanges = exclusionRanges;

// Create a green plot area

//创建绿色区域

CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease];

dataSourceLinePlot.identifier = @"Green Plot";

//设置绿色区域边框的样式

CPMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];

lineStyle.lineWidth = 3.f;

lineStyle.lineColor = [CPColor greenColor];

lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.0f], [NSNumber numberWithFloat:5.0f], nil];

dataSourceLinePlot.dataLineStyle = lineStyle;

//设置数据元代理

dataSourceLinePlot.dataSource = self;

// Put an area gradient under the plot above

CPColor *areaColor = [CPColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8];

//设置区域的颜色,第一个为结束颜色,第二个为开始颜色

CPGradient *areaGradient = [CPGradient gradientWithBeginningColor:areaColor endingColor:[CPColor clearColor]];

areaGradient.angle = -90.0f;

CPFill *areaGradientFill = [CPFill fillWithGradient:areaGradient];

dataSourceLinePlot.areaFill = areaGradientFill;

dataSourceLinePlot.areaBaseValue = CPDecimalFromString(@"2");//填充的范围,通常设置为y轴的最大范围

// Animate in the new plot, as an example

dataSourceLinePlot.opacity = 0.0f;//设置开的透明度, 然后会有动画

dataSourceLinePlot.cachePrecision = CPPlotCachePrecisionDecimal;

[graph addPlot:dataSourceLinePlot];//简短添加一个默认的曲线到默认的曲线空间。

CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

fadeInAnimation.duration = 1.0f;

fadeInAnimation.removedOnCompletion = NO;

fadeInAnimation.fillMode = kCAFillModeForwards;

fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];//动画最终结束的值

[dataSourceLinePlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];

// Create a blue plot area

CPScatterPlot *boundLinePlot = [[[CPScatterPlot alloc] init] autorelease];

boundLinePlot.identifier = @"Blue Plot";

lineStyle = [[boundLinePlot.dataLineStyle mutableCopy] autorelease];

lineStyle.miterLimit = 1.0f;

lineStyle.lineWidth = 3.0f;

lineStyle.lineColor = [CPColor blueColor];

lineStyle = lineStyle;

boundLinePlot.dataSource = self;

boundLinePlot.cachePrecision = CPPlotCachePrecisionDouble;

boundLinePlot.interpolation = CPScatterPlotInterpolationHistogram;

[graph addPlot:boundLinePlot];

// Do a blue gradient

CPColor *areaColor1 = [CPColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8];

CPGradient *areaGradient1 = [CPGradient gradientWithBeginningColor:areaColor1 endingColor:[CPColor clearColor]];

areaGradient1.angle = -90.0f;

areaGradientFill = [CPFill fillWithGradient:areaGradient1];

boundLinePlot.areaFill = areaGradientFill;

boundLinePlot.areaBaseValue = [[NSDecimalNumber zero] decimalValue];

// Add plot symbols 在坐标处添加一个点

CPMutableLineStyle *symbolLineStyle = [CPMutableLineStyle lineStyle];

symbolLineStyle.lineColor = [CPColor blackColor];

CPPlotSymbol *plotSymbol = [CPPlotSymbol ellipsePlotSymbol];

plotSymbol.fill = [CPFill fillWithColor:[CPColor blueColor]];

plotSymbol.lineStyle = symbolLineStyle;

plotSymbol.size = CGSizeMake(10.0, 10.0);

boundLinePlot.plotSymbol = plotSymbol;

//dataSourceLinePlot.plotSymbol = plotSymbol;

// Add some initial data//添加坐标的临时数据

NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];

NSUInteger i;

for ( i = 0; i < 60; i++ ) {

id x = [NSNumber numberWithFloat:1+i*0.05];

id y = [NSNumber numberWithFloat:1.2*rand()/(float)RAND_MAX + 1.2];//2147483647

[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];

}

self.dataForPlot = contentArray;

}

你可能感兴趣的:(F#)