更改条形图设计[iOS图表]
我已经使用中的更改条形图设计[iOS图表],ios,swift,charts,ios-charts,Ios,Swift,Charts,Ios Charts,我已经使用中的BarChartView创建了一个条形图,但我不知道如何更改条形图的设计 我使用的设计在图片的右侧,而我需要实现左侧设计 如果您有任何帮助,我们将不胜感激。目前,无法按照您想要的方式更改酒吧设计 然而,也有人尝试过类似的方法,通过改变网格线来绘制横杆,但没有添加网格线。 请参阅:。 你可以看看他的作品 另一种手动解决方法,虽然不是最好的,但如果您确实需要,应该可以使用,就是在图表视图(或任何其他UIView)的顶部放置一个带不透明线条的透明视图 例子: 用法: 请注意,这将在图
BarChartView
创建了一个条形图,但我不知道如何更改条形图的设计
我使用的设计在图片的右侧,而我需要实现左侧设计
如果您有任何帮助,我们将不胜感激。目前,无法按照您想要的方式更改酒吧设计 然而,也有人尝试过类似的方法,通过改变网格线来绘制横杆,但没有添加网格线。
请参阅:。
你可以看看他的作品 另一种手动解决方法,虽然不是最好的,但如果您确实需要,应该可以使用,就是在
图表视图
(或任何其他UIView
)的顶部放置一个带不透明线条的透明视图
例子:
用法:
请注意,这将在
图表视图上显示的任何内容上画一条线
所以,如果您决定显示条形图数据标签,那么线条也会在其上绘制
我希望这对你有所帮助:)你能分享一些你当前实现的代码吗?请检查我更新了帖子@格鲁梅
@IBOutlet weak var charts: BarChartView!
charts.chartDescription?.enabled = false
charts.isUserInteractionEnabled = false
//charts.maxVisibleCount = 10
charts.drawBarShadowEnabled = false
charts.legend.enabled = false
let xAxis = charts.xAxis
xAxis.labelPosition = .bottom
xAxis.labelTextColor = .white
charts.xAxis.drawGridLinesEnabled = false
charts.rightAxis.drawGridLinesEnabled = false
charts.rightAxis.drawLabelsEnabled = false
charts.leftAxis.drawGridLinesEnabled = false
charts.leftAxis.drawLabelsEnabled = false
charts.leftAxis.axisMinimum = 0 ///
charts.rightAxis.axisMinimum = 0
charts.fitBars = true
charts.legend.textColor = .white
charts.setBarChartData(xValues: time, yValues: data, label: "Bar Chart")
class HorizontalLines: UIView {
override func draw(_ rect: CGRect) {
//number of parts to divide the height of view by
let segments = 20
//number of lines ignoring the bottom most line
let numberOfLines = segments - 1
//draw the lines from left to right
for i in (1...numberOfLines).reversed() {
let multiplier = CGFloat(i)/CGFloat(segments)
let y = rect.size.height * multiplier
let startPoint = CGPoint(x:0, y:y)
let endPoint = CGPoint(x:rect.size.width, y:y)
let aPath = UIBezierPath()
aPath.move(to: startPoint)
aPath.addLine(to: endPoint)
aPath.close()
//line width
aPath.lineWidth = 1
aPath.stroke()
aPath.fill()
}
}
}
let lineView = HorizontalLines()
lineView.isUserInteractionEnabled = false
lineView.backgroundColor = .clear
lineView.translatesAutoresizingMaskIntoConstraints = false
chartView.addSubview(lineView)
lineView.leadingAnchor.constraint(equalTo: chartView.leadingAnchor).isActive = true
lineView.trailingAnchor.constraint(equalTo: chartView.trailingAnchor).isActive = true
lineView.topAnchor.constraint(equalTo: chartView.topAnchor).isActive = true
lineView.bottomAnchor.constraint(equalTo: chartView.bottomAnchor).isActive = true