danielgindi/Charts饼状图pieChartView用法
来源:互联网 发布:网络正常微博刷新不了 编辑:程序博客网 时间:2024/05/29 12:49
#import "PieChartsView.h"#import "ChartsDemo-Bridging-Header.h"#import "ChartsDemo-swift.h"#define kSelfWidth self.frame.size.width#define kSelfHeight self.frame.size.height@implementation PieChartsView { PieChartView *_pieChartView;}- (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self uiConfig]; } return self;}- (void)uiConfig { _pieChartView = [[PieChartView alloc] init]; _pieChartView.backgroundColor = [UIColor cyanColor]; _pieChartView.frame = CGRectMake(0, 0, kSelfWidth, kSelfHeight); _pieChartView.holeRadiusPercent = 0.4; // 中间空心半径比 _pieChartView.transparentCircleRadiusPercent = 0; _pieChartView.chartDescription.enabled = NO; [_pieChartView setExtraOffsetsWithLeft:5.f top:10.f right:5.f bottom:5.f]; ChartLegend *l = _pieChartView.legend; l.horizontalAlignment = ChartLegendHorizontalAlignmentRight; l.verticalAlignment = ChartLegendVerticalAlignmentTop; l.orientation = ChartLegendOrientationVertical; l.formSize = 10; l.font = [UIFont systemFontOfSize:10]; [self addSubview:_pieChartView]; // 开始设值 NSDictionary *statistics = @{ @"初步接洽":[NSNumber numberWithLong:27], @"需求确定":[NSNumber numberWithLong:11], @"方案报价":[NSNumber numberWithLong:8], @"谈判审核":[NSNumber numberWithLong:3], }; NSMutableArray *values = [NSMutableArray array]; //累加总数, 为了算百分比 double total = 0; for (NSNumber *num in statistics.allValues) { total += [num doubleValue]; } // 循环字典数组 创建data for (NSString *str in statistics.allKeys) { NSNumber *value = statistics[str]; if ([value intValue] != 0) { [values addObject:[[PieChartDataEntry alloc] initWithValue:[value doubleValue]/total*100 label:str]]; } } // 循环data数组 创建Set if (values.count > 0) { PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithValues:values label:@""]; dataSet.sliceSpace = 2.0; //设置饼块颜色数组 dataSet.colors = @[[UIColor blueColor], [UIColor brownColor], [UIColor redColor], [UIColor orangeColor]]; PieChartData *data = [[PieChartData alloc] initWithDataSet:dataSet]; NSNumberFormatter *pFormatter = [[NSNumberFormatter alloc] init]; pFormatter.numberStyle = NSNumberFormatterPercentStyle; pFormatter.maximumFractionDigits = 1; pFormatter.multiplier = @1.f; [data setValueFormatter:[[ChartDefaultValueFormatter alloc] initWithFormatter:pFormatter]]; [data setValueFont:[UIFont systemFontOfSize:8]]; [data setValueTextColor:UIColor.whiteColor]; _pieChartView.data = data; [_pieChartView highlightValues:nil]; }}@end
Demo下载地址: http://download.csdn.NET/detail/margaret_mo/9720571
0 0
- danielgindi/Charts饼状图pieChartView用法
- danielgindi/Charts折线lineChartView用法
- danielgindi/Charts柱形图barChartView使用
- 手动导入swift三方danielgindi/Charts到OC工程中教程
- hellocharts-android图表库之饼状图:PieChartView
- charts
- charts
- charts
- iOS-Charts框架使用用法浅析
- HelloChart--PieChartView(饼图)
- HelloChart--PieChartView(饼图)
- iOS使用Charts框架绘制—饼状图
- iOS使用Charts框架绘制—饼状图
- iOS使用Charts框架绘制—饼状图
- iOS使用Charts框架绘制—饼状图
- iOS Charts框架绘制折线图、统计饼状图
- Charts 资料
- d3 charts
- 学习笔记——处理器管理(1)
- Spring Boot 初学者笔记
- c++中构造函数初始化的方法以及主要区别
- 【备忘】新浪微博Android客户端开发完整视频 下载
- 第7章 复用类
- danielgindi/Charts饼状图pieChartView用法
- ffmpeg转换参数和压缩输出大小的比率 参考 最新版本FFMPEG
- mysql-5.7.17-winx64.zip 的安装与配置
- Zsh报错: zsh: command not found:tree
- LintCode 61-搜索区间
- VMware中ubuntu忘记密码的解决办法
- HashMap学习笔记
- Can a Compound Index serve multiple queries
- 【备忘】北风网Android应用实战淘宝网手机客户端全程实录 下载