首先,建立一个用来画饼图的视图。
头文件:
#import <Foundation/Foundation.h>
@interface PieView : UIView {
}
@end
实现文件:
#import "PieView.h"
@implementation PieView
#define PI 3.14159265358979323846
#define radius 100
static inline float radians(double degrees) {
return degrees * PI / 180;
}
static inline void drawArc(CGContextRef ctx, CGPoint point, float angle_start, float angle_end, UIColor * color) {
CGContextMoveToPoint(ctx, point.x, point.y);
CGContextSetFillColor(ctx, CGColorGetComponents([color CGColor]));
CGContextAddArc(ctx, point.x, point.y, radius, angle_start, angle_end, 0);
CGContextFillPath(ctx);
}
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
float angle_start = radians(0.0);
float angle_end = radians(121.0);
drawArc(ctx, self.center, angle_start, angle_end, [UIColor yellowColor]);
angle_start = angle_end;
angle_end = radians(228.0);
drawArc(ctx, self.center, angle_start, angle_end, [UIColor greenColor]);
angle_start = angle_end;
angle_end = radians(260);
drawArc(ctx, self.center, angle_start, angle_end, [UIColor orangeColor]);
angle_start = angle_end;
angle_end = radians(360);
drawArc(ctx, self.center, angle_start, angle_end, [UIColor purpleColor]);
}
@end
然后,将刚建立的视图加到当前视图上即可。
- (void)viewDidLoad {
[super viewDidLoad];
PieView *pie = [[PieView alloc] init];
pie.frame = [[UIScreen mainScreen] bounds];
[self.view addSubview:(UIView *) pie];
[pie release];
}
示例图:
分享到:
相关推荐
JS 完美画饼图,JS 完美画饼图,JS 完美画饼图
数据分析,画饼图的jupyter notebook代码
asp实现画饼图功能,很有用哦,asp实现画饼图功能,很有用哦
【ASP.NET】按比例画饼图 一个很简单的实例
画饼图 使用html5加javascript技术生成饼图 简单容易理解
C#354-画饼图组件源代码
根据省份位置,在Echarts 地图上画饼图, 可点击放大单个饼图
javascript raphael 画饼图,很方便 很简单 很容易懂!不用更改代码,直接写相应的html格式就好了!全自动生成饼图
一个画饼图的小程序。是立体的效果的,,也可以平面图。。
android achat画饼图,柱图,抽出了chatenginer的柱图和饼图并重写
用CSS绘制饼图,针对移动端上的展示,建议在谷歌浏览器上打开效果更佳,上传了两个html文件,pie.html是css静态画饼图,pieAuto.html是用我自己写的插件可以根据传入的参数动态绘制饼图
MFC饼图类,不支持VC6,如需要修改,请找作者。
LabVIEW中实现饼图显示,提供比较好的人机界面
纯js画饼状图,只需要创建表格,使用非常简单
该DEMO用于绘制饼图,圆弧。根据百分比可以以不同颜色分割饼图。
自定义控件饼状图,android版本,github上的源代码,共享给大家
听说你不会用python画饼图?赶紧进来看一下刚出炉的教程
画饼图组件
此程序主要是用C语言编写的,用TC运行更加方便。可以实现饼图数据自行输入~
iOS 画饼图、折线图、柱状图