piecharts (iOS charts) not displayed in custom tableviewcell
I test your code. It works fine.
And the middle hole, maybe it's the configuration problem. Try to add this
pieChartDataSet.drawIconsEnabled = false
pieChartDataSet.sliceSpace = 1
pieChartDataSet.highlightColor = UIColor.white
pieChartDataSet.entryLabelColor = UIColor.white
pieChartDataSet.selectionShift = 0
pieChartView.holeRadiusPercent = 0.5
pieChartView.transparentCircleRadiusPercent = 0.0
Hope this helps
plotting sine and cosine with charts have kinks
Here:
let ys1 = Array(0..<10).map { x in return sin(Double(x)) }
let ys2 = Array(0..<10).map { x in return cos(Double(x)) }
let yse1 = ys1.enumerated().map { x, y in return ChartDataEntry(x: Double(x), y: y) }
let yse2 = ys2.enumerated().map { x, y in return ChartDataEntry(x: Double(x), y: y) }
You are only using 10 values. It is not that surprising that the curve is not smooth. Even though you are doing ds1.mode = .cubicBezier
, but the Charts library can only do so much smoothing for you. This line is not a magic spell.
To make the curve more smooth, we can use more values of sin(x) and cos(x) that are closer together. Instead of 10, let's use 100 values from 0 to 10, with a step of 0.1 each time.
let ys1 = Array(0..<100).map { x in ChartDataEntry(x: Double(x) / 10, y: sin(Double(x) / 10)) }
let ys2 = Array(0..<100).map { x in ChartDataEntry(x: Double(x) / 10, y: cos(Double(x) / 10)) }
Multiple charts in same view IOS Charts
You need to create prototype cells for each of the types of charts, which you want to use in your TableView. In each prototype cell you need to put UIView and then change the class of UIView to LineChartView, BarChartView, etc.
Also you need to define your own class for each prototype cell, e.g:
class MyLineChartCell: UITableViewCell {
@IBOutlet weak var lineChartView: LineChartView!
func configure (/* ... */) {
lineChartView.noDataText = "You have no data"
// ...
}
}
.
Use this classes for you prototype cells:
Then in func func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
you could choose which prototype will be used at the moment.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyLineChartCellIdentifier") as! MyLineChartCell
cell.configure(/* Data, Colors, etc. */)
}
if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyBarChartCellIdentifier") as! MyBarChartCell
cell.configure(/* Data, Colors, etc. */)
}
//... some other types of cells
return cell
}
UITableViewCell subviews are displaying outside of cell
Ended up adding
for case let cell as UITableViewCell in tableView.subviews {
for subview in cell.contentView.subviews {
if subview.tag == 115 {
subview.removeFromSuperview()
}
}
}
to my didSelectRowAt
method, after adding the tag when each view is created. I'm still not sure why the views were being added to different cells, but this got rid of them at least.
Swift iOS TableView cell items disappears when scrolling
Within your UITableViewCell
subclass, override prepareForReuse with:
badgeIcon.hidden = true
This way you can use a "clean slate" when configuring your cells upon reuse.
Related Topics
How to Handle Menu Button Action in Tvos Remote
Sharing File Data Between Applications in Swift/Ios
Why Do Two Distinct Array Literals Equal Each Other in Swift
How to Incorporate Swift Package Manager to an Existing Xcode Project
Swift Optional Type: How .None == Nil Works
Swift 4.2 - _Shared Attribute Near Type
Accessing Global Variable in Swift
Extending Typed Array by Conforming to a Protocol in Swift 2
Saving Swifty JSON Array to User Defaults
Passing Data from Simple Nsview to Swiftui View
Handling an Attribute of an Xml Element in Swift
Is There a Way I Can Combine a Geofirestore Query with a Normal Firestore Query
Swift Lazy Stored Property Versus Regular Stored Property When Using Closure
Uiimagepickercontroller Navigation Bar Tint Color Not Working with iOS 13
Swift: For-In Loop Requires '[Deepspeechtokenmetadata]' to Conform to 'Sequence'