0
我想創建條形圖。我使用Charts庫,這是我對viewDidLoad()
只有第一個標籤添加到BarChart
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]
xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
代碼我的問題是,只有第一條具有在X軸的標籤是「揚」。
這是使用setData代碼
func setDataCount(count: Int, range: Double){
let barWidth = 8.5
let spaceForBar = 10.0;
var yVals = [BarChartDataEntry]()
yVals.append(BarChartDataEntry(x: Double(0) * spaceForBar, y: 9.1))
yVals.append(BarChartDataEntry(x: Double(1) * spaceForBar, y: 5.4))
yVals.append(BarChartDataEntry(x: Double(2) * spaceForBar, y: 3.9))
var set1 : BarChartDataSet!
if let count = barChartView.data?.dataSetCount, count > 0{
set1 = barChartView.data?.dataSets[0] as! BarChartDataSet
set1.values = yVals
barChartView.data?.notifyDataChanged()
barChartView.notifyDataSetChanged()
}else{
set1 = BarChartDataSet(values: yVals, label: "")
var dataSets = [BarChartDataSet]()
dataSets.append(set1)
let data = BarChartData(dataSets: dataSets)
data.barWidth = barWidth;
barChartView.data = data
}
}
您可以在條形圖上看到多少條酒吧? 1或12? – CodeChanger
我看到我在yVals上追加的3個酒吧 –
你檢查我的答案嗎? – CodeChanger