答案 0 :(得分:2)
您可以将索引移动0.5并将xAxis.axisMinimum设置为0.0:
var entries: [BarChartDataEntry] = []
for index in 0..<datapoints.count {
let value1 = Double(datapoints[index])
let value2 = Double(datapoints[index])
entries.append(BarChartDataEntry(x: Double(index)+0.5, yValues: [value1, value2]))
}
let xvalues = ["1", "2"]
combinedChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: xvalues)
combinedChart.xAxis.labelPosition = Charts.XAxis.LabelPosition.bothSided
let set = BarChartDataSet(values: entries, label: " - Description.")
combinedChart.xAxis.axisMinimum = 0.0
set.axisDependency = Charts.YAxis.AxisDependency.left
data.addDataSet(set)
答案 1 :(得分:0)
您还可以使用偏移量
combinedChart.xAxis.xOffset = -0.5
我不确定该值是否适合您的情况。尝试一下。
答案 2 :(得分:0)
有两种方法可以完成这项工作。
第一种方法
chartView.setExtraOffsets(left: 20, top: 0, right: 0, bottom: 0)
第二种方法
chartView.xAxis.avoidFirstLastClippingEnabled = true