How to remove the value label above each bar in bar chart for ios-charts

一曲冷凌霜 提交于 2019-12-10 03:02:17

问题


Each bar has a value above it, but whenever I get too many data entries graphed, these values are spilling over into each other and making themselves unreadable. The only way to edit these that I could find was setting them to either above or below each bar. However I would like to hide them completely. How do I do this in swift?


回答1:


There is a method called setDrawValues which allows you to enable or disable the label text. Here an example in Swift with LineChart:

xValues = ["1","2"]
yValues = [54.0, 42.0]

var dataEntries: [ChartDataEntry] = []

for i in 0..<xValues.count {
   let dataEntry = ChartDataEntry(value: yvalues[i], xIndex: i)
   dataEntries.append(dataEntry)
}

let lineChartDataSet = LineChartDataSet(yVals: dataEntries, label: "YourData")
let lineChartData = LineChartData(xVals: xValues, dataSet: lineChartDataSet)

// this disables the display of the labels - be sure to apply it to your LineChartData object
lineChartData.setDrawValues(false)

Edit: For sure in your case you can use this method also for your BarChartData object.

Documentation can be found here (ios-charts is based on MPAndroidChart and therefore has more or less the same functionality): https://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.2.3/javadoc/com/github/mikephil/charting/data/ChartData.html#setDrawValues(boolean)




回答2:


You can disable the labels by adding the following line;

lineData.setDrawValues(false)



回答3:


You can use drawValuesEnabled as below :

let chartDataSet = BarChartDataSet(yVals: dataEntries, label: nil)
chartDataSet.drawValuesEnabled = false



回答4:


In swift3 following line can do the job:

chartDataSet.valueTextColor = UIColor.clear



回答5:


This does the trick for Swift 4

yourChartDataSet.drawValuesEnabled = false



回答6:


Set this flag to True or False

_chart.drawValueAboveBarEnabled = YES;


来源:https://stackoverflow.com/questions/36193312/how-to-remove-the-value-label-above-each-bar-in-bar-chart-for-ios-charts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!