需要在iOS中为漏斗图创建自定义控件(在Swift或Objective-C中)。
找到了很少的图书馆:这里是链接:https://github.com/ayudasystems/funnel
计划使用BezierPath实现漏斗图。
请建议需要实现此控件的数据结构。
**注意-搜索大量帖子,但dint找到了在ios中实现漏斗图的确切解决方案(那里的帖子很少,但答案不正确或不被接受)
最佳答案
您必须使用简单的逻辑来实现上述漏斗图。
共有5个项目:A1,A2,A3,A4,A5,并且漏斗的高度为 200 。
&& A1 = 30%,A2 = 25%,A3 = 20%,A4 = 15%和A5 = 10%
Now distritribute items according to height % in funnel. So
A1 = 0.3*200 = 60
A2 = 0.25*200 = 50
A3 = 0.2*200 = 40
A4 = 0.15*200 = 30
A5 = 0.1*200 = 20
--------------------
Total = 200
On the basis of above calculated height:- 5 different BezierPath can be drawn .
Above data can be generalised to 'n' items and 'x' Height .
的逻辑计算高度分布
class HeightDistribution {
class func height(percentages: [Float] , TotalHeight:Float ) -> [Float]
{
var heights = [Float]()
for percentage in percentages
{
let height = (percentage/100)*TotalHeight
heights.append(height)
}
return heights
}
}
Progress Demo Funnel Chart app || Swift3
关于ios - 在iOS中创建漏斗图?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39160208/