组合图表。 Swift 2.2

Combined Charts. Swift 2.2

我正在尝试在条形图上创建折线图。到目前为止我有以下代码:

class AnalysisViewController: UIViewController, ChartViewDelegate {
func setChart(xValues: [String], valuesBarChart: [Double], valuesLineChart: [Double]) {
    barChartView.descriptionText = ""
    barChartView.noDataText = "You need to provide data for the chart."

    var yValsBarChart: [BarChartDataEntry] = []
    var yValsLineChart : [ChartDataEntry] = [ChartDataEntry]()

    for i in 0..<xValues.count {

        yValsBarChart.append(BarChartDataEntry(value: valuesBarChart[i], xIndex: i))
        yValsLineChart.append(ChartDataEntry(value: valuesLineChart[i] - 1, xIndex: i))
    }

    let lineChartDataSet = LineChartDataSet(yVals: yValsLineChart, label: nil)
    let barChartDataSet = BarChartDataSet(yVals: yValsBarChart, label: nil)

    let data: CombinedChartData = CombinedChartData(xVals: xValues)

    data.barData = BarChartData(xVals: xValues, dataSets: [barChartDataSet])
    data.lineData = LineChartData(xVals: xValues, dataSets: [lineChartDataSet])

    barChartView.data = data

    barChartView.leftAxis.customAxisMin = 0

    UniversalStatic.data.generateColoursForGraph(budgetName.count)
    barChartDataSet.colors = UniversalStatic.data.colourArrayForGraph


    setDesignChart()
}
}

我在终端上收到以下错误:

无法将类型 'Charts.CombinedChartData' (0x3d5d70) 的值转换为 'Charts.BarChartData' (0x3cfc54)。

以及:

我真的不知道我做错了什么,因为我没有触及出现错误的 'BarChartView'。

任何帮助将不胜感激:)

因为我最初是先创建条形图然后尝试添加折线图,所以我忘记将视图从 BarChartView 更改为 CombinedChartView!