CSPieChart
示例
要运行示例项目,请克隆仓库,并首先从示例目录运行 pod install
。
需求
安装
CSPieChart 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod "CSPieChart"
用法
第一步 - 将CSPieChart
导入到您的项目中
第二步 - 应导入 CSPieChartData
。这是饼图的模型。
let data = CSPieChartData(key: "test", value: 70)
第三步 - 到您的类中添加代理 CSPieChartDataSource
和 CSPieChartDelegate
,并添加两个代理方法
public protocol CSPieChartDataSource {
/// Component data
func numberOfComponentData() -> Int
func pieChart(_ pieChart: CSPieChart, dataForComponentAt index: Int) -> CSPieChartData
/// Component colors
func numberOfComponentColors() -> Int
func pieChart(_ pieChart: CSPieChart, colorForComponentAt index: Int) -> UIColor
/// If you are implement this, you can show subView. example) 'UIImageView' or 'UILable'
@objc optional func numberOfComponentSubViews() -> Int
@objc optional func pieChart(_ pieChart: CSPieChart, viewForComponentAt index: Int) -> UIView
/// If you are implement this, you apply color to line path
/// Otherwish line color is applied default 'black'
@objc optional func numberOfLineColors() -> Int
@objc optional func pieChart(_ pieChart: CSPieChart, lineColorForComponentAt index: Int) -> UIColor
}
public protocol CSPieChartDelegate {
/// Component select
@objc optional func pieChart(_ pieChart: CSPieChart, didSelectComponentAt index: Int)
}
您可以设置一些选项
// Pie chart radius rate that is percentage of frames in the superview. default is 0.7
public var pieChartRadiusRate: CGFloat = 0.7
// Pie chart line length between component and subview. default is 10
public var pieChartLineLength: CGFloat = 10
// This is piechart component selecting animation. default is none
public var seletingAnimationType: SelectingAnimationType = .none
}
最后一步 - 您必须调用 show
。
示例
func ViewDidLoad(...) {
....
pieChart.show(animated: true)
}
如需更多信息,请查看示例
作者
chansim.youk, [email protected]
许可协议
CSPieChart适用于MIT许可协议。请参阅LICENSE文件以获取更多信息。