Charts Not Plotting in Tableviewcell

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.

Set class for view

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:
Set class for cell

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



Leave a reply



Submit