我想创建一个自定义图表。
这将在 Y 轴上显示数学的数量,例如4
Y 轴图例将是开始日期和结束日期。
X 轴上的折线图将绘制每场比赛状态的点,例如
赢了, 画, 损失。
如何在 Objective C 中做到这一点!??
最佳答案
要创建折线图,我们只需要一个 UIBezier 路径和一个 CAShapeLayer,将基于您拥有的数据的坐标点传递到将创建折线图的 UiBezierpath,然后将该路径添加到图层。
下面是创建折线图的代码,
//Bezier path for ploting graph
_graphPath = [[UIBezierPath alloc]init];
[_graphPath setLineWidth:10];
//CAShapeLayer for graph allocation
_graphLayout = [CAShapeLayer layer];
_graphLayout.frame = CGRectMake(self.frame.size.width*0, 0, self.frame.size.width*0.8, (self.frame.size.height*0.9));
_graphLayout.fillColor = [[UIColor colorWithRed:0 green:0 blue:255 alpha:0.1] CGColor];
_graphLayout.strokeColor = [UIColor blueColor].CGColor;
_graphLayout.lineWidth = 2;
_graphLayout.path = [_graphPath CGPath];
_graphLayout.lineCap = @"round";
_graphLayout.lineJoin = @"round";
[self.layer addSublayer:_graphLayout];
点加线和移动点的代码
[_graphPath moveToPoint:CGPointMake(coord.x, coord.y)];
[_graphPath addLineToPoint:CGPointMake(coord.x, coord.y)];
_graphLayout.path = [_graphPath CGPath];
关于ios - 如何在 ios 中绘制折线图?任何可以帮助我在 ios 中显示图形数据的控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963336/