在X轴上添加字符串数组(月)-swift

时间:2019-04-19 14:08:34

标签: swift charts

我相信Swift 5,Xcode 10.2.1,Cocoapod 3.3图表

我正在创建调查折线图,但无法弄清楚如何通过X轴标签的month数组(monthArray)。当月份为String时,它请求Double。数组被填充,图表工作正常。我选择了一个年份并键入,它可以正确填充。

Graph image

let values = (0..<count).map { (i) -> ChartDataEntry in

        switch typeSelected {

        case "timliness":
           let val = timeArray[i]
           print(timeArray[i])
           return ChartDataEntry(x: Double(i), y: val)

        case "ease":
           let val = easeArray[i]
           return ChartDataEntry(x: Double(i), y: val)

        case "positive":
           let val = positiveArray[i]
            return ChartDataEntry(x: Double(i), y: val)

        case "process":
           let val = processArray[i]
            return ChartDataEntry(x: Double(i), y: val)

        case "engagement":
           let val = engagementArray[i]
            return ChartDataEntry(x: Double(i), y: val)

        default:
           let val = overallArray[i]
           return ChartDataEntry(x: Double(i), y: val)
        }

    }

    let set1 = LineChartDataSet(entries: values, label: yearSelected + " - " + displeyLabel )

    let data = LineChartData(dataSet: set1)

    self.lineChartView.data = data

0 个答案:

没有答案