3 Star 0 Fork 0

Gitee 极速下载 / VBPieChart

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/sakrist/VBPieChart
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

License

VBPieChart

Animated Pie Chart control for iOS apps, based on CALayer. Very easy in use and have custom labeling.

Usage

Create simple pi chart with VBPieChart:

VBPieChart *chart = [[VBPieChart alloc] initWithFrame:CGRectMake(10, 50, 300, 300)];
[self.view addSubview:chart];

// Setup some options:
[chart setEnableStrokeColor:YES]; 
[chart setHoleRadiusPrecent:0.3]; /* hole inside of chart */

// Prepare your data
NSArray *chartValues = @[
 @{@"name":@"Apples", @"value":@50, @"color":[UIColor redColor]},
 @{@"name":@"Pears", @"value":@20, @"color":[UIColor blueColor]},
 @{@"name":@"Oranges", @"value":@40, @"color":[UIColor orangeColor]},
 @{@"name":@"Bananas", @"value":@70, @"color":[UIColor purpleColor]}
];

// Present pie chart with animation
[chart setChartValues:chartValues animation:YES duration:0.4 options:VBPieChartAnimationFan];

chartValues needs to be defined as an array of dictionaries.
Dictionary required to contain value for piece with key value.
Optional:

  • name
  • color
  • labelColor
  • accent
  • strokeColor

Chart from JSON

VBPieChart *chart = [[VBPieChart alloc] initWithFrame:CGRectMake(10, 50, 300, 300)];
chart.startAngle = M_PI+M_PI_2;
chart.holeRadiusPrecent = 0.5;
[self.view addSubview:chart];
NSString *json_example = @"[ {\"name\":\"first\", \"value\":\"50\", \"color\":\"#84C69B\", \"strokeColor\":\"#fff\"}, \
{\"name\":\"second\", \"value\":\"60\", \"color\":\"#FECEA8\", \"strokeColor\":\"#fff\"}, \
{\"name\":\"second\", \"value\":\"75\", \"color\":\"#F7EEBB\", \"strokeColor\":\"#fff\"}, \
{\"name\":\"second\", \"value\":\"90\", \"color\":\"#D7C1E0\", \"strokeColor\":\"#fff\"} ]";

NSData *data = [json_example dataUsingEncoding:NSUTF8StringEncoding];
NSArray *chartValues = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

[chart setChartValues:chartValues animation:YES duration:0.5 options:VBPieChartAnimationFan];

Chart with custom label position

VBPieChart *chart = [[VBPieChart alloc] initWithFrame:CGRectMake(10, 50, 300, 300)];
chart.startAngle = M_PI+M_PI_2;
chart.holeRadiusPrecent = 0.5;
[self.view addSubview:chart];
[chart setLabelsPosition:VBLabelsPositionCustom];
[chart setLabelBlock:^CGPoint( CALayer *layer, NSInteger index) {
    CGPoint p = CGPointMake(sin(-index/10.0*M_PI)*50+50, index*30);
    return p;
}];

[chart setChartValues:@[
                         @{@"name":@"37%", @"value":@65, @"color":@"#5677fcaa", @"labelColor":@"#000"},
                         @{@"name":@"13%", @"value":@23, @"color":@"#2baf2baa", @"labelColor":@"#000"},
                         @{@"name":@"19.3%", @"value":@34, @"color":@"#b0bec5aa", @"labelColor":@"#000"},
                         @{@"name":@"30.7%", @"value":@54, @"color":@"#f57c00aa", @"labelColor":@"#000"}
                         ]
             animation:YES];

Basic Documentation

VBPieChart is subclass of UIView.

Properties

length
Length of circle pie. Min values is 0 and max value 2*M_PI.

startAngle
Start angle of pie. (M_PI will make start at left side)

holeRadiusPrecent
hole radius in % of whole radius. Values 0..1. (acual hole radius will be calculated radius*holeRadiusPrecent)

radiusPrecent
Defines the radius, full radius = frame.size.width/2, actual radius = full radius*radiusPrecent. Value 0..1.

labelBlock
Block will help to redefine positions for labels.

Methods

Get all changed chart values back.
- (NSArray *) chartValues;

Simple setup data.
- (void) setChartValues:(NSArray *)chartValues;

Setup data to pie chart with animation or not, animation options and duration.
- (void) setChartValues:(NSArray *)chartValues animation:(BOOL)animation duration:(float)duration options:(VBPieChartAnimationOptions)options;

Animation options:

  • VBPieChartAnimationFanAll
  • VBPieChartAnimationGrowth
  • VBPieChartAnimationGrowthAll
  • VBPieChartAnimationGrowthBack
  • VBPieChartAnimationGrowthBackAll
  • VBPieChartAnimationFan
  • VBPieChartAnimationTimingEaseInOut
  • VBPieChartAnimationTimingEaseIn
  • VBPieChartAnimationTimingEaseOut
  • VBPieChartAnimationTimingLinear

Change value for elemet at index. Value will be changed with animation.
- (void) setValue:(NSNumber*)value pieceAtIndex:(NSInteger)index;

Insert new piece at index. Animated. - (void) insertChartValue:(NSDictionary*)chartValue atIndex:(NSInteger)index;

Remove piece at index.
- (void) removePieceAtIndex:(NSInteger)index;

Supported with ad:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
MIT License Copyright (c) 2017 Volodymyr Boichentsov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

VBPieChart 是 iOS 饼图控件,带有不同的动画效果 展开 收起
Ruby
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Ruby
1
https://gitee.com/mirrors/VBPieChart.git
git@gitee.com:mirrors/VBPieChart.git
mirrors
VBPieChart
VBPieChart
master

搜索帮助