NRSPieChart
示例
要运行示例项目,首先克隆仓库,然后在示例目录中运行pod install
。
要求
安装
NRSPieChart可通过CocoaPods获得。要安装它,仅需在Podfile中添加以下行
pod "NRSPieChart"
作者
Neil Schreiber,[email protected]
许可证
NRSPieChart遵循MIT许可证。有关更多信息,请参阅LICENSE文件。
功能
- 支持大于和小于的扇区
- 选择并突出显示扇区
- 动画显示扇区大小和颜色变化
- 可在界面构建器(IBInspectable)中进行配置
用法
###基本图表
@property (weak) IBOutlet NRSPieChartView *pieChartView;
#pragma mark - PieChartViewDataSource
- (NSUInteger) numberOfMajorSlicesInPieChartView:(NRSPieChartView *)pieCharView {
return 10; // Total number of major slices
}
- (NSUInteger) numberOfMinorSlicesInPieChartView:(NRSPieChartView *)pieCharView forMajorSlice:(NSUInteger)majorSlice {
return 1; // Number of minor slices per major slice
}
- (CGColorRef) pieChartColorForSlice:(NRSPieChartView *)pieChartView sliceIndex:(NRSPieChartViewSliceIndex * _Nonnull)sliceIndex {
return [UIColor redColor] CGColor]; // Return the color for the given major.minor slice
}
- (NRSPieChartViewEndPoints *) pieChartEndPointsForSlice:(NRSPieChartView *)pieChartView sliceIndex:(NRSPieChartViewSliceIndex * _Nonnull)sliceIndex {
return [[NRSPieChartViewEndPoints alloc] initWithStart:(10 + 0.05) end:(30 - 0.05)];j // Return an "End Point", based on 0...100 range. 0 corresponds to 12 o'clock position in chart
}
- (BOOL)pieChartShouldHighlightSlice:(NRSPieChartView *)pieChartView sliceIndex:(NRSPieChartViewSliceIndex *)sliceIndex {
return NO; // return if given slice should be highlighted. Highlighted slices are displayed with extend width
}
#pragma mark - PieChartViewDelegate
- (void)pieChartDidSingleTapSlice:(NRSPieChartView *)pieChartView sliceIndex:(NRSPieChartViewSliceIndex *)sliceIndex {
// called on single tap of chart. Example, can capture selection here and use that highlight the tapped slice. NOTE: remember to refresh pieChart in order to show the highlighted slice.
[pieChartView refreshSlices];
}