iOS绘制额外空间并添加x轴标签

时间:2017-09-04 20:14:37

标签: ios swift charts ios-charts

我一直在使用iOS Charts来创建条形图。这就是我到目前为止所做的:

我无法实现三件事:

  • 将x轴标签从(0-7)更改为星期一,星期二,星期三等
  • 摆脱酒吧上方的标签(1.0,10.0,20等)
  • 如何摆脱柱子与底部轴之间的空间

非常感谢帮助其中任何一个

3 个答案:

答案 0 :(得分:2)

请分享您的代码。

问题1:

 var xvalues: [String] = [String]()

 for i in 0 ..< datapoints.count {               
    xvalues.append("custom text here")
 }

 barchartview.xAxis.valueFormatter = IndexAxisValueFormatter(values: xvalues)

问题2:

    let dataSet = BarChartDataSet()
    dataSet.values = barChartDataEntries

    // to hide values above the bars
    dataSet.drawValuesEnabled = false        

    let data = BarChartData(dataSet: dataSet)
    barchartview.data = data

答案 1 :(得分:2)

请查看以下内容:

将x轴标签从(0-7)更改为星期一,星期二,星期三等:

var weekdays: [String] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: weekdays)

去除栏上方的标签(1.0,10.0,20等):

let chartDataSet = BarChartDataSet(values: dataEntries, label: "")
chartDataSet.drawValuesEnabled = false

用于衬里到xAxis:

barChartView.rightAxis.axisMinimum = 0.0
barChartView.leftAxis.axisMinimum = 0.0

答案 2 :(得分:0)

lineChartView.leftAxis.axisMinimum = 0
lineChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: weekdays)