简体   繁体   English

如何删除ios图表条形图中每个条形图上方的值标签

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

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? 我如何在swift中执行此操作?

There is a method called setDrawValues which allows you to enable or disable the label text. 有一个名为setDrawValues的方法,允许您启用或禁用标签文本。 Here an example in Swift with LineChart: 这里是Swift与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. 编辑:在您的情况下,您可以将此方法也用于BarChartData对象。

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) 文档可以在这里找到(ios-charts基于MPAndroidChart,因此具有或多或少相同的功能): https ://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.2.3/javadoc/com/github/ mikephil /图表/数据/ ChartData.html#setDrawValues(布尔值)

您可以通过添加以下行来禁用标签;

lineData.setDrawValues(false)

You can use drawValuesEnabled as below : 您可以使用drawValuesEnabled,如下所示:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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