以下內(nèi)容是從開源庫自帶的例子中選出的有實(shí)用性的高級用法及部分代碼
CPTLineCap類:箭頭指示器
例如:
CPTXYGraph *newGraph = [[CPTXYGraph alloc] initWithFrame:bounds];
CPTXYAxisSet *xyAxisSet = (CPTXYAxisSet *)newGraph.axisSet;
CPTXYAxis *xAxis = xyAxisSet.xAxis;
CPTLineCap *lineCap = [[CPTLineCap alloc] init];
?lineCap.lineStyle = xAxis.axisLineStyle;?
?lineCap.lineCapType = CPTLineCapTypeSweptArrow;
?lineCap.size = CGSizeMake(12.0, 15.0);?
lineCap.fill = [CPTFill fillWithColor:xAxis.axisLineStyle.lineColor]; xAxis.axisLineCapMax = lineCap;
CPTGradient類:負(fù)責(zé)填充色
例如:
CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] initWithFrame:newGraph.bounds];
CPTColor *areaColor = [CPTColor colorWithComponentRed:CPTFloat(1.0) green:CPTFloat(1.0) blue:CPTFloat(1.0) alpha:CPTFloat(0.6)];?
?CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]]; areaGradient.angle = -90.0;?
?CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient];
dataSourceLinePlot.areaFill = areaGradientFill;
dataSourceLinePlot.areaBaseValue = CPTDecimalFromDouble(0.0);
其中朝聋,areaBaseValue為設(shè)置該填充顏色從哪個(gè)值開始描述,上例就是從(0,0)開始填充囤躁。
areaFill和areaFill2共兩個(gè)填充冀痕,一個(gè)填充上面一個(gè)填充下面的顏色荔睹。
CPTTradingRangePlot類:每個(gè)折點(diǎn)用圖片和文字展示具體數(shù)值
CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle]; whiteLineStyle.lineColor = [CPTColor whiteColor]; whiteLineStyle.lineWidth = 2.0;
CPTTradingRangePlot *ohlcPlot = [[CPTTradingRangePlot alloc] initWithFrame:newGraph.bounds];?
?ohlcPlot.identifier = @"OHLC";?
?ohlcPlot.lineStyle = whiteLineStyle; //向上或向下的線條?
ohlcPlot.plotStyle = CPTTradingRangePlotStyleCandleStick; ohlcPlot.shadow = whiteShadow;?
?ohlcPlot.labelShadow = whiteShadow;?
?[newGraph addPlot:ohlcPlot];
效果如下:
CPTLegend類:條目說明(不同顏色柱狀的說明)
CPTLegend *theLegend = [CPTLegend legendWithGraph:graph]; theLegend.fill = [CPTFill fillWithColor:[CPTColor colorWithGenericGray:CPTFloat(0.15)]];?
?theLegend.borderLineStyle = barLineStyle;?
?theLegend.cornerRadius = 10.0;?
?theLegend.swatchSize = CGSizeMake(16.0, 16.0);?
?CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];?
?whiteTextStyle.color = [CPTColor whiteColor];
?whiteTextStyle.fontSize = 12.0;?
?theLegend.textStyle = whiteTextStyle;?
?theLegend.rowMargin = 10.0;?
?theLegend.numberOfRows = 1;
?theLegend.paddingLeft = 12.0; theLegend.paddingTop = 12.0;
?theLegend.paddingRight = 12.0; theLegend.paddingBottom = 12.0;?
?graph.legend = theLegend; graph.legendAnchor = CPTRectAnchorBottom;?
?graph.legendDisplacement = CGPointMake(0.0, 5.0);
Bar Plot 1和Bar Plot 2就是條目說明。
CPTPlotSymbol類:折線的節(jié)點(diǎn)用圓點(diǎn)顏色標(biāo)注金度,如果需要展示數(shù)值時(shí)应媚,和CPTTradingRangePlot類類似,可以2選1
例如:
?CPTMutableLineStyle * symbolLineStyle = [CPTMutableLineStyle lineStyle];
?symbolLineStyle.lineColor = [CPTColor blackColor]; symbolLineStyle.lineWidth = 2.0;?
?CPTPlotSymbol * plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];?
?plotSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]];?
?plotSymbol.lineStyle = symbolLineStyle;?
?plotSymbol.size = CGSizeMake(10.0, 10.0);
dataSourceLinePlot.plotSymbol = plotSymbol;
圖例:
注:可以參考以下blog猜极,注釋較細(xì)
CPTScatterPlot類:畫折線中姜,也能畫直線,可用于類似數(shù)據(jù)統(tǒng)計(jì)的中心線跟伏,高位線丢胚,警告線
繪制時(shí)主要的dataSource的兩個(gè)代理方法:
1、numberOfRecordsForPlot: 返回散射點(diǎn)個(gè)數(shù)
2受扳、-(NSNumber*)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnumrecordIndex:(NSUInteger)index 或者?
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index等携龟,都是為了讓CorePlot知道每個(gè)散射點(diǎn)的具體值(x,y)。
第1個(gè)參數(shù)指定要繪制的圖形對象(CPTPlot)勘高,第2個(gè)參數(shù)指定當(dāng)前正在繪制的點(diǎn)的字段名(代表x坐標(biāo)或y坐標(biāo))峡蟋,第3個(gè)參數(shù)表示正在繪制第幾個(gè)點(diǎn)。
示例圖: