Rotated pie chart for iOS

Source: Internet
Author: User
Tags flock

:



Code download: http://pan.baidu.com? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> flock + sf3NvLXEtdrI/blend + c1_vcd4kpha + flock + CjxwcmUgY2xhc3M9" brush: java; "> # import # Import "PieChartView. h" @ interface ViewController: UIViewController @ Property (nonatomic, strong) NSMutableArray * m_valueArray; // container of the first group of data @ property (nonatomic, strong) NSMutableArray * m_colorArray; // container of the first group of colors @ property (nonatomic, strong) NSMutableArray * m_valueArray2; // container of the second set of data @ property (nonatomic, strong) optional * m_colorArray2; // container of the second set of colors @ property (nonatomic, strong) PieChartView * m_piechar; // pie chart class @ property (nonatomic, strong) UIView * m_pieContainer; // the container of the pie chart @ property (nonatomic) BOOL inOut; // click the control switch in the center @ property (nonatomic, strong) UILabel * m_selLabel; // display data label @ end
ViewController. m

//// ViewController. m // rotated pie chart /// Created by du jia on 14-3-24. // Copyright (c) June 2014 dujia. all rights reserved. // # import "ViewController. h "# define PIE_HEIGHT 280 @ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {self. inOut = YES; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self. m_valueArray = [[NSMutableArray alloc] initWi ThObjects: [NSNumber numberWithInt: 12], [NSNumber numberWithInt: 3], [NSNumber numberWithInt: 2], [NSNumber numberWithInt: 3], [NSNumber numberWithInt: 3], [NSNumber numberWithInt: 4], nil]; self. m_valueArray2 = [[NSMutableArray alloc] initWithObjects: [NSNumber numberWithInt: 3], [NSNumber numberWithInt: 2], [NSNumber numberWithInt: 2], nil]; self. m_colorArray = [NSMutableArray arrayWithObjects: [UIColor ColorWithHue :( (0/8) % 20)/20.0 + 0.08 saturation :( 0% 8 + 3)/10.0 brightness: 91/100. 0 alpha: 1], [UIColor colorWithHue :( (1/8) % 20)/20.0 + 0.03 saturation :( 1% 8 + 3)/10.0 brightness: 91/100. 0 alpha: 1], [UIColor colorWithHue :( (2/8) % 20)/20.0 + 0.12 saturation :( 2% 8 + 3)/10.0 brightness: 91/100. 0 alpha: 1], [UIColor colorWithHue :( (3/8) % 20)/20.0 + 0.32 saturation :( 3% 8 + 3)/10.0 brightness: 91/100. 0 alpha: 1], [UIColor colorWithHu E :( (4/8) % 20)/20.0 + 0.01 saturation :( 4% 8 + 3)/10.0 brightness: 91/100. 0 alpha: 1], [UIColor colorWithHue :( (5/8) % 20)/20.0 + 0.05 saturation :( 5% 8 + 3)/10.0 brightness: 91/100. 0 alpha: 1], nil]; self. m_colorArray2 = [NSMutableArray alloc] custom: [UIColor purpleColor], [UIColor orangeColor], [UIColor magentaColor], nil]; // add shadow img CGRect pieFrame = CGRectMake (self. view. frame. size. width-PIE_HE IGHT)/2, 0, PIE_HEIGHT, PIE_HEIGHT); UIImage * shadowImg = [UIImage imageNamed: @ "shadow.png"]; UIImageView * handle = [[UIImageView alloc] initWithImage: shadowImg]; shadowImgView. frame = CGRectMake (0, pieFrame. origin. y + PIE_HEIGHT * 0.92, shadowImg. size. width/2, shadowImg. size. height/2); [self. view addSubview: shadowImgView]; self. m_pieContainer = [[UIView alloc] initWithFrame: pieFrame]; self. m _ PieChartView = [[PieChartView alloc] initWithFrame: self. m_pieContainer.bounds withValue: self. m_valueArray withColor: self. m_colorArray]; self. m_pieChartView.delegate = self; [self. m_pieContainer addSubview: self. m_pieChartView]; [self. m_pieChartView setAmountText: @ "-2456.0"]; [self. view addSubview: self. m_pieContainer]; // add selected view UIImageView * selView = [[UIImageView alloc] init]; selView. ima Ge = [UIImage imageNamed: @ "select.png"]; selView. frame = CGRectMake (self. view. frame. size. width-selView. image. size. width/2)/2, self. m_pieContainer.frame.origin.y + self. m_pieContainer.frame.size.height, selView. image. size. width/2, selView. image. size. height/2); [self. view addSubview: selView]; self. m_selLabel = [[UILabel alloc] initWithFrame: CGRectMake (0, 24, selView. image. size. width/2, 21)]; self. M_selLabel.backgroundColor = [UIColor clearColor]; self. m_selLabel.textAlignment = NSTextAlignmentCenter; self. m_selLabel.font = [UIFont systemFontOfSize: 17]; self. m_selLabel.textColor = [UIColor whiteColor]; [selView addSubview: self. m_selLabel]; [self. m_pieChartView setTitleText: @ "Total expenditure"]; self. title = @ "statement";}-(void) selectedFinish :( PieChartView *) pieChartView index :( NSInteger) index percent :( flo At) per {self. m_selLabel.text = [NSString stringWithFormat: @ "% 2.2f % @", per * 100, @ "%"];}-(void) onCenterClick :( PieChartView *) pieChartView {self. inOut =! Self. inOut; self. Reflect = nil; [self. m_pieChartView removeFromSuperview]; self. m_pieChartView = [[PieChartView alloc] initWithFrame: self. Adjust withValue: self. inOut? Self. m_valueArray: self. m_valueArray2 withColor: self. inOut? Self. m_colorArray: self. m_colorArray2]; self. m_pieChartView.delegate = self; [self. m_pieContainer addSubview: self. m_pieChartView]; [self. m_pieChartView reloadChart]; if (self. inOut) {[self. m_pieChartView setTitleText: @ "Total expenditure"]; [self. m_pieChartView setAmountText: @ "-2456.0"];} else {[self. m_pieChartView setTitleText: @ "total revenue"]; [self. m_pieChartView setAmountText: @ "+ 567.23"] ;}}- (void) viewDidAppear :( BOOL) animated {[self. m_pieChartView reloadChart];}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} @ end


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.