iOS图表中的圆条 [英] Rounded bars in ios Charts

查看:77
本文介绍了iOS图表中的圆条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ios图表中的BarChartView创建了条形图,但我不知道出如何在圆棒上添加圆角.

I've created a BarChart using BarChartView from ios-Charts but I can't figure out howto add rounded corners to bars.

这是我正在使用的代码:

This is the code that I'm using:

let barChart: BarChartView
//...
var xVals = [String]()
var yVals = [BarChartDataEntry]()
//...

let set1 = BarChartDataSet(yVals: yVals, label: "Label")

set1.drawValuesEnabled = false
set1.highlightLineWidth = 3
set1.colors = [UIColor.whiteColor()]

barChart.data = BarChartData(xVals: xVals, dataSet: set1)

我一直在寻找要设置的属性,例如set1.barCornerRadius,但没有找到任何东西.

I've looked for a property like set1.barCornerRadius to set, but I didn't find anything.

这是我所拥有的:

这是我需要的:

推荐答案

BarChartRenderer.swift中,您可以修改open func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int)

然后有if-statement条用于堆积和未堆积的条形,选择您的箱子并取出:

Then there's if-statement for stacked and nonstacked bars, choose your case and remove:

context.fill(barRect)

并添加:

let bezierPath = UIBezierPath(roundedRect: barRect, cornerRadius: %YOUR_CORNER_RADIUS%)
context.addPath(bezierPath.cgPath)

context.drawPath(using: .fill)

这篇关于iOS图表中的圆条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆