CorePlot折线图部分高级用法

以下内容是从开源库自带的例子中选出的有实用性的高级用法及部分代码


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类:负责填充色


例如:

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为设置该填充颜色从哪个值开始描述,上例就是从(0,0)开始填充。

areaFill和areaFill2共两个填充,一个填充上面一个填充下面的颜色。


CPTTradingRangePlot类:每个折点用图片和文字展示具体数值

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类:折线的节点用圆点颜色标注,如果需要展示数值时,和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,注释较细

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


CPTScatterPlot类:画折线,也能画直线,可用于类似数据统计的中心线,高位线,警告线


绘制时主要的dataSource的两个代理方法:

1、numberOfRecordsForPlot: 返回散射点个数

2、-(NSNumber*)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnumrecordIndex:(NSUInteger)index 或者 

-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index等,都是为了让CorePlot知道每个散射点的具体值(x,y)。

第1个参数指定要绘制的图形对象(CPTPlot),第2个参数指定当前正在绘制的点的字段名(代表x坐标或y坐标),第3个参数表示正在绘制第几个点。

示例图:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值