图表-图形绘制后立即消失

时间:2019-01-22 12:36:19

标签: ios swift charts

Graph Plotted

Graph Disappeared immediatly

图形在绘制后立即消失。我无处将图形数据设置为nil。这是我的代码。我尝试在Google上搜索类似问题,但未找到任何有用的链接或问题。

func updateChartData() {

    let yValues = self.modelController.getChartData()
    guard !yValues.isEmpty else { return }

    var dataSets = [LineChartDataSet]()

    for i in 0..<yValues.count{
        let yVals = yValues[i]
        let dataSet = LineChartDataSet(values: yVals, label: nil)
        dataSet.axisDependency = .left
        dataSet.setColor(UIColor.asTurquoiseBlue)
        dataSet.setCircleColor(UIColor.asTurquoiseBlue)
        dataSet.lineWidth = 1
        dataSet.circleRadius = 5
        dataSet.circleHoleColor = .white
        dataSet.drawCircleHoleEnabled = true

        if i == yValues.count - 1 {
            let gradientColors = [UIColor.asPaleBlue.cgColor, UIColor.white.cgColor]
            let colorLocations:[CGFloat] = [1.0,0.0]
            if let gradient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: gradientColors as CFArray, locations: colorLocations){
                let fill = Fill.fillWithLinearGradient(gradient, angle: 90)
                dataSet.fill = fill
            }
            dataSet.drawFilledEnabled = true
        }else{
            dataSet.drawFilledEnabled = false
        }
        dataSets.append(dataSet)
    }

    let data = LineChartData(dataSets: dataSets)
    data.setValueTextColor(.darkGray)
    data.setValueFont(.systemFont(ofSize: 9))
    data.setDrawValues(false)
    self.chartView.data = data
    self.chartView.animate(xAxisDuration: 1, easingOption: .easeInBack)
}

0 个答案:

没有答案