注意:目前仅支持饼图,但欢迎提出需求!
包含源代码和一个完全工作的通用应用项目。
(请先查看core-plot,以确保它不是您想要的,Chartreuse非常轻量级。)
基本上,从PieChartViewExample/Classes/
目录中获取两个主要文件(PieChartView.[h|m]
)并将其添加到您的项目中(或创建子模块或类似项目)。然后
// Set a gradient to start 1/3 from the top, and continue to the bottom
[_pieChart setGradientFillStart:0.3 andEnd:1.0];
// Use black 0.7 opaque for our gradient
[_pieChart setGradientFillColor:PieChartItemColorMake(0.0, 0.0, 0.0, 0.7)];
// Create three data items to show in our pie chart
[_pieChart addItemValue:0.4 withColor:PieChartItemColorMake(1.0, 0.5, 1.0, 0.8)];
[_pieChart addItemValue:0.3 withColor:PieChartItemColorMake(0.5, 1.0, 0.5, 0.8)];
[_pieChart addItemValue:0.3 withColor:PieChartItemColorMake(0.5, 0.5, 1.0, 0.8)];
// If the piechart is hidden, show it
[_pieChart setHidden:NO];
// Force the drawRect: method to be called
[_pieChart setNeedsDisplay];
或者如果您想渐显饼图,可以这样做:
_pieChart.alpha = 0.0;
[_pieChart setHidden:NO];
[_pieChart setNeedsDisplay];
// Animate the fade-in
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
_pieChart.alpha = 1.0;
[UIView commitAnimations];