How to hide labels in ios-charts?
self.chartView.xAxis.drawGridLinesEnabled = false
self.chartView.leftAxis.drawLabelsEnabled = false
self.chartView.legend.enabled = false
will do the job
Swift iOS Charts - Hide certain Bar Chart value labels
You just need to provide your custom IValueFormatter
to BarChartData
as below,
public class XValueFormatter: NSObject, IValueFormatter {
public func stringForValue(_ value: Double, entry: ChartDataEntry, dataSetIndex: Int, viewPortHandler: ViewPortHandler?) -> String {
return value <= 0.0 ? "" : String(describing: value)
}
}
let chartData = BarChartData(dataSet: yourSet)
chartData.setValueFormatter(XValueFormatter())
Note: String(describing: value)
is just to provide a workable example. You can apply proper number formatter to convert Double
into String
.
Hide inner label in pieChart Charts pod swift
So you're trying to hide "value" label. And for that, you need to set drawValuesEnabled = false for your dataset.
I think "value label" is being mixed up with "entry label" and "center text", so check out the image for your better understanding.
// label inside the circle
pieChart.centerText = "center text"
// dataset for the pie chart
let data = PieChartDataSet(entries: [
PieChartDataEntry(value: 100, label: "entry label")
])
// hides entry label
pieChart.drawEntryLabelsEnabled = false
// set clear color for entry label = hides entry label
pieChart.entryLabelColor = .clear
// hides center text
pieChart.drawCenterTextEnabled = false
// hides value label
data.drawValuesEnabled = false
pieChart.data = PieChartData(dataSet: data)
Remove Value Labels from iOS Charts Pie Chart
If you need to disable drawing values of Data Set Entries use this
pieChartDataSet.drawValuesEnabled = false
If you need to disable drawing values on some Axis use this:
chartIMG.rightAxis.drawLabelsEnabled = false
chartIMG.leftAxis.drawLabelsEnabled = false
chartIMG.xAxis.drawLabelsEnabled = false
chartIMG.rightAxis.drawLabelsEnabled = false
iOS Charts remove values on the bar of the bar chart
Add following line of code where you setup sets of chart to fix your issue:
var set = BarChartDataSet(values: yVals, label: "Data Set")
set.drawValuesEnabled = false // Set this property to false to hide all values
let data = BarChartData(dataSet: set)
yourChartView.data = data
This code will hide all values above bar chart. I hope this will help you.
How can I remove Description Label in ios-chart?
It's descriptionText
, not description
, description
is NSObject
variable
On Swift 3.0 and Chart 3.0:
barchart.chartDescription?.text = ""
Allow PieChartView to hide labels for tiny slices in Swift
Create a custom formatter, I set the minNumber as 10.0 and the empty string is returned when a value is less than the minNumber, otherwise the value is returned.
public class ChartFormatter: NSObject, IValueFormatter{
public func stringForValue(_ value: Double, entry: ChartDataEntry, dataSetIndex: Int, viewPortHandler: ViewPortHandler?) -> String {
let total = UserDefaults.standard.double(forKey: "totalValue")
var valueToUse = value/total * 100
valueToUse = Double(round(10*valueToUse)/10)
print("valueToUse: \(valueToUse)")
let minNumber = 10.0
if(valueToUse<minNumber) {
return ""
}
else {
return String(valueToUse) + "%"
}
}
}
Then make sure you set the totalValue variable, store it in UserDefaults (to make it possible to access it in the formatter) and set the formatter for your graph
var totalValue = 0.0
let units = [10.0, 4.0, 6.0, 3.0, 12.0, 16.0]
for a in units {
totalValue += a
}
UserDefaults.standard.set(totalValue, forKey: "totalValue")
let formatter:ChartFormatter = ChartFormatter()
data.setValueFormatter(formatter)
Result:
Related Topics
Coreplot with Swift: There Is No Yaxis.Majorintervallength
Apply Vertical Alpha Gradient to Uitableview
How to Display Realm Results in Swiftui List
Uiscrollview with Embedded Uiimageview; How to Get the Image to Fill the Screen
Extend Existing Protocols to Implement Another Protocol with Default Implements
How to Conform to Nscopying and Implement Copywithzone in Swift 2
In Swift, How to Have a Uiscrollview Subclass That Has an Internal and External Delegate
Dynamically Change Text of Realitykit Entity
Custom Swift Encoder/Decoder for the Strings Resource Format
How to Detect Vertical Planes in Arkit
Implicitly Lazy Static Members in Swift
How to Reproduce This Xcode Blue Drag Line
Swift Package Manager - Uikit Dependency
Reference as Key in Swift Dictionary
Anonymous Closure Argument Not Contained in a Closure
Single-Element Parethesized Expressions/Tuples VS Common Use of Parentheses