如何在iOS中绘制折线图?任何可以帮助我在ios中显示图形数据的控件 [英] how to draw a line graph in ios? Any control which will help me show graph data in ios

查看:191
本文介绍了如何在iOS中绘制折线图?任何可以帮助我在ios中显示图形数据的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义图.

I want to create a customized graph.

这将在Y轴上显示算术数,例如4

Which will show on Y axis number of mathces e.g. 4

Y轴图例将是开始日期和结束日期.

Y axis legends will be the starting date and ending date.

在X轴上,折线图将在每个匹配项的状态上绘制点.例如

And on X axis a line graph will plot the points on the status of the each match E.g.

赢, 画, 损失.

如何在目标C中做到这一点!?

How to do this in Objective C!??

推荐答案

要创建折线图,我们只需要一个UIBezier路径和一个CAShapeLayer,将基于您拥有的数据的坐标点传递到将创建折线的UiBezierpath图,然后将该路径添加到图层.

To create line graph just we need one UIBezier path and one CAShapeLayer, pass the co ordinate points based on the data you have to the UiBezierpath that will create the line graph then add that path to layer.

这是创建折线图的代码,

Here is the code to create line graph,

//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];

添加线到点并移动到点的代码

The code to add line to point and move to point

[_graphPath moveToPoint:CGPointMake(coord.x, coord.y)];
[_graphPath addLineToPoint:CGPointMake(coord.x, coord.y)];
_graphLayout.path = [_graphPath CGPath];

这篇关于如何在iOS中绘制折线图?任何可以帮助我在ios中显示图形数据的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆