在iPhone中创建简单的线图
我想创建一个简单的线图,如下所示在iPhone中创建简单的线图,iphone,ios,cocoa-touch,graph,linegraph,Iphone,Ios,Cocoa Touch,Graph,Linegraph,我想创建一个简单的线图,如下所示 我在谷歌上搜索了一些样本,得到的CorePlot看起来太重了。谁能建议我如何创建一种像下面或教程一样的线图也是最受欢迎的。请好吧,首先,为什么说这个图很简单?可以通过沿X坐标绘制垂直线来实现。您(可能)有一个带有顶点(显示权重进度)的数组,因此在一个循环中从顶点到基线绘制一条线,该循环将解析所有顶点。下面是画一条线的代码,为每个顶点调用它: -(void)drawLineFromX:(CGPoint)topPoint{ UIGraphicsBeginI
我在谷歌上搜索了一些样本,得到的CorePlot看起来太重了。谁能建议我如何创建一种像下面或教程一样的线图也是最受欢迎的。请好吧,首先,为什么说这个图很简单?可以通过沿X坐标绘制垂直线来实现。您(可能)有一个带有顶点(显示权重进度)的数组,因此在一个循环中从顶点到基线绘制一条线,该循环将解析所有顶点。下面是画一条线的代码,为每个顶点调用它:
-(void)drawLineFromX:(CGPoint)topPoint{
UIGraphicsBeginImageContext(instanceToYourImageView.image.size);
[instanceToYourImageView.image drawInRect:CGRectMake(0, 0, instanceToYourImageView.image.size.width, instanceToYourImageView.image.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y + a_value_to_reach_the_base_line);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[instanceToYourImageView setImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
这里是CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0,0.0,1.0)
为黑色,但您可以轻松地将其更改为所需的颜色
干杯 或者您可以使用此功能其中一种可能性是