【发布时间】:2020-03-03 00:42:36
【问题描述】:
我正在使用这个例子在 iOS 上创建一个饼图: https://www.highcharts.com/ios/demo/pie-gradient
饼图渲染良好,但渐变填充仅为黑色。我将示例中的代码转换为 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)"]])
]
在给定的示例中,他们已将颜色数组分配给 options.colors,但它只需要字符串数组而不是 HIColor 数组。这是我得到的错误: error.png
为了修复错误,这是我尝试的代码修改,它给出了黑色派:
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
我们将不胜感激。
【问题讨论】:
标签: ios swift highcharts pie-chart radial-gradients