[英]iOS Swift Highcharts Pie with Gradient Fill is black
I am using this example to create a pie chart on iOS: https://www.highcharts.com/ios/demo/pie-gradient我正在使用此示例在 iOS 上创建饼图: https : //www.highcharts.com/ios/demo/pie-gradient
The pie chart renders fine but the gradient fill is only black color.饼图呈现良好,但渐变填充仅为黑色。 I converted the code in example to Swift like this:
我将示例中的代码转换为 Swift,如下所示:
let colors = [
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#7cb5ec" ],[1, "rgb(48,105,160)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#434348" ],[1, "rgb(0,0,0)"]])!,
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#90ed7d" ],[1, "rgb(68,161,49)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#f7a35c" ],[1, "rgb(171,87,16)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#8085e9" ],[1, "rgb(52,57,157)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#f15c80" ],[1, "rgb(165,16,52)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#e4d354" ],[1, "rgb(152,135,8)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#2b908f" ],[1, "rgb(0,68,67)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#f45b5b" ],[1, "rgb(168,15,15)"]]),
HIColor(radialGradient: ["cx": 0.5, "cy": 0.3,"r": 0.7],
stops: [[ 0, "#91e8e1" ],[1, "rgb(69,156,149)"]])
]
In the given example, they have assigned colors array to options.colors but it takes only String array and not HIColor array.在给定的示例中,他们将颜色数组分配给 options.colors 但它只需要 String 数组而不是 HIColor 数组。 Here's the error I am getting: error.png
这是我得到的错误: error.png
In order to fix the error, here's the code modification I tried which gives black colored pie:为了修复错误,这是我尝试的代码修改,它给出了黑色的饼图:
let colors_str = colors.map{
(color: HIColor!) -> String in
let c = color.getData().debugDescription
.replacingOccurrences(of: "Optional(", with: "")
.replacingOccurrences(of: "\n", with: "")
.replacingOccurrences(of: "\"", with: "")
.dropLast()
let value = String(c)
return value
}
options.colors = colors_str
Any help will be highly appreciated.任何帮助将不胜感激。
I found the solution to this problem.我找到了这个问题的解决方案。 Wanted to post it since I spent a day on it and in case someone else faces the same issue.
想发布它,因为我花了一天的时间,以防其他人面临同样的问题。 So the code of iOS on Highcarts samples is incorrect.
所以iOS在Highcarts样本上的代码是不正确的。 I referred to the Javascript code of same pie and found out that colors is assigned to plot options pie color.
我参考了同一个饼图的 Javascript 代码,发现颜色被分配给了绘图选项饼图颜色。 Here's the sample code in swift:
这是 swift 中的示例代码:
let plot_options = HIPlotOptions()
plot_options.pie = HIPie()
plot_options.pie.colors = colors as? [HIColor]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.