简体   繁体   中英

Horizontal Bar chart Swift

I want it like this:

在此处输入图片说明

But what I can do is, how to get rid of little red label: 在此处输入图片说明

Core code for the chart:

var barchart = [BarChartDataEntry]()
// some values
barchart.append(value1)
barchart.append(value2)
barchart.append(value3)

let barData = BarChartDataSet(values: barchart, label: "")
barData.colors = [NSUIColor.red]
let data = BarChartData(dataSet: barData)
data.barWidth = 0.35
cell.barChart.data = data
cell.barChart.scaleYEnabled = false
cell.barChart.chartDescription?.text = ""
cell.barChart.scaleXEnabled = false
cell.barChart.pinchZoomEnabled = false
cell.barChart.doubleTapToZoomEnabled = false
cell.barChart.rightAxis.enabled = false
cell.barChart.xAxis.drawGridLinesEnabled = false
cell.barChart.leftAxis.drawGridLinesEnabled = false
cell.barChart.leftAxis.drawAxisLineEnabled = false
cell.barChart.xAxis.drawAxisLineEnabled = false
cell.barChart.xAxis.drawLabelsEnabled = false
cell.barChart.leftAxis.drawLabelsEnabled = false
cell.barChart.animate(yAxisDuration: 1.5, easingOption: .easeInOutQuart)
return cell

I would like to set max value and make labels rounded as in the image above. I am using https://github.com/danielgindi/Charts .

You can implement the similar UI by using the UIProgressView

First, you can set the Label on top, then a UIProgressView and repeat the same. For other two progresses.

You can add the proper constraints and achieve it.

Refer this Sample Demo for achieving the same.

Hope it helps.

Just add this line where you are setting chartView

cell.barChart.legend.enabled = false

It works for me.

Use UIProgressView component in storyboard and create the outlet

@IBOutlet var progressViewWalk: UIProgressView!

You can set the required progress by:-

progressViewWalk.progress = Float(YOURValue)/100

Set your required Track tint color Progress tint color in Attribute Inspector .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM