CorePlot折線圖高級用法

以下內(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ì)

http://longshuaili123.wap.blog.163.com/w2/blogDetail.do;jsessionid=A17F2F45F621C78D5E2CFEC55EF1784C.blog160-8010?blogId=fks_087067092081083069083081080070072084088068093080087065082&showRest=true&p=5&hostID=longshuaili123


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)。

示例圖:


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容