图表,Horizo​​ntalBarChartView,如何设置值alignment = Center?

时间:2017-06-26 12:35:06

标签: ios swift charts bar-chart

Swift 3.1,图表,tableViewHorizontalBarChartView的多个单元格。 是否有可能使价值中心对齐? enter image description here

设置图表数据:

   func refreshData() {

    guard let item = self.item, !item.tasks.isEmpty else {
        return
    }

    self.titleName.text = item.name
    self.leftNameMargin.constant = CGFloat(30 * item.level)
    self.titleName.textColor = UIColor(hexString: item.color)

    let font = UIFont.systemFont(ofSize: 17.0, weight: UIFontWeightSemibold)

    var colors:  [UIColor] = []
    var yValues: [Double]  = []
    var count = 0.0

    for task in item.tasks {
        count += Double(task.count)
        yValues.append(Double(task.count))
        colors.append(UIColor(hexString: task.valueColor))
    }

    let suffix = String(format: NSXLocalization.string(forKey: KEY_STR_PERCENT)) //fixes '%' duplication
    let formatter = NumberFormatter()
    formatter.roundingMode = .floor
    formatter.numberStyle = .percent
    formatter.positiveSuffix = suffix
    formatter.negativeSuffix = suffix
    formatter.zeroSymbol = ""

    let dataEntry = BarChartDataEntry(x: 0.0, yValues: yValues.map { ($0 / count) })
    let dataSet = BarChartDataSet(values: [dataEntry], label: nil)
    dataSet.colors = colors
    dataSet.valueTextColor = .white
    dataSet.barBorderColor = .black
    dataSet.barBorderWidth = 1.0
    dataSet.drawValuesEnabled = true
    dataSet.valueFormatter = DefaultValueFormatter(formatter: formatter)

    let data = BarChartData(dataSets: [dataSet])
    data.setValueFont(font)
    data.setDrawValues(true)
    data.highlightEnabled = true

    self.chart.data = data
}

我查看了图表中的所有内部方法,但从未找到过将y值居中的方法。

0 个答案:

没有答案