【问题标题】:iOS Swift Highcharts Pie with Gradient Fill is black带有渐变填充的 iOS Swift Highcharts Pie 是黑色的
【发布时间】: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

black-pie-chart

我们将不胜感激。

【问题讨论】:

    标签: ios swift highcharts pie-chart radial-gradients


    【解决方案1】:

    我找到了解决这个问题的方法。想发布它,因为我花了一天时间在上面,以防其他人面临同样的问题。所以 Highcarts 样本上的 iOS 代码是不正确的。我参考了同一个饼图的 Javascript 代码,发现颜色被分配给绘图选项饼图颜色。这是swift中的示例代码:

     let plot_options = HIPlotOptions()
     plot_options.pie = HIPie()
     plot_options.pie.colors = colors as? [HIColor]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多