我想在 Swift 3 中显示图表,但为什么月份名称没有显示,是否有人编码?
@IBOutlet var utilizationChart: LineChartView!
override func viewDidLoad() {
super.viewDidLoad()
let months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 18.0, 19.0, 21.0, 24.0, 30.0, 16.0]
setChart(dataPoints: months, values: unitsSold)
utilizationChart.chartDescription?.text = ""
utilizationChart.backgroundColor = UIColor.clear
utilizationChart.noDataText = "No chart data available"
}
func setChart(dataPoints: [String], values: [Double]) {
utilizationChart.delegate = self
var dataEntries: [ChartDataEntry] = []
for i in 0..<values.count {
let dataEntry = ChartDataEntry(x: Double(i), y: values[i])
dataEntries.append(dataEntry)
}
let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Utilization")
let lineChartData = LineChartData(dataSet: lineChartDataSet)
utilizationChart.data = lineChartData
}