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?
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)
您可以通过添加以下行来禁用标签;
lineData.setDrawValues(false)
You can use drawValuesEnabled as below :
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: nil)
chartDataSet.drawValuesEnabled = false
在swift3中,以下行可以完成这项工作:
chartDataSet.valueTextColor = UIColor.clear
这对Swift 4来说很有用
yourChartDataSet.drawValuesEnabled = false
将此标志设置为True或False
_chart.drawValueAboveBarEnabled = YES;
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.