gpt4 book ai didi

ios - echarts(iOS图表)未显示在自定义uitableviewcell中

转载 作者:行者123 更新时间:2023-11-29 05:19:49 26 4
gpt4 key购买 nike

screenshot

我遇到饼图未显示在自定义表格 View 单元格中的问题。 TableView 单元格是通过 Storyboard添加的,每个单元格包含一个小图标图像、两个标签和一个 UIView,我在 View 检查器中将其设置为 PieChartView。

两个标签中的小图标图像和文本显示良好,没有问题。然而,对于饼图,我没有收到任何错误消息,但只是没有显示任何图表。表格显示出来,在标签中填充了正确的文本,但饼图 View 除了饼图的中间孔之外是空的。当我单击其中一个时,会显示饼图 View - 不完全正确(仅显示两个饼图切片之一,另一部分丢失)。

因此,触摸事件使切片可见,但我希望在运行行函数的单元格时,所有单元格都可以看到饼图。

我已经添加了 tableviewcontroller 和 tableviewcell 的代码。如果有人能指出我的错误,那就太好了。我研究并尝试了很多,其中包括以下堆栈溢出资源: Charts not plotting in tableViewCell iosChart not displaying LineChartView points in UITableViewCell Adding a SubView to UITableViewCell doesn't get displayed How to implement iOS Chart in a tableview cell?

截图显示了我点击几个不可见的饼图后的情况。它们变得可见,当我向下滚动表格时,随机单元格中的更多(并非全部)饼图可见,有些则不可见。

tableviewcontroller 的代码:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "easyAndDiffAllWordsCell", for: indexPath) as! BVBResultsDiffAndEasyAllWordsGraphTableViewCell

let easyVoc = parsedInEasyVocStructures[indexPath.row]

//get the current voc for the writings
let currentVoc = BVBVocabularyManager.getVoc()

cell.label1.text = currentVoc.kanji

cell.label2.text = currentVoc.kanji2

let image = UIImage(named: "plus")
cell.plusMinusImage.image = image

//set the percentages
cell.percentageSolved = arrayOfSuccessPercentagesForPieChart
cell.percentageNotSolved = arrayOfNegativeSuccessPercentagesForPieChart

cell.setChart(forIndexNo:indexPath.row, dataPoints: months, valuesSolved: arrayOfSuccessPercentagesForPieChart, valuedNonSolved: arrayOfNegativeSuccessPercentagesForPieChart)

cell.setNeedsDisplay()
cell.pieChartView.clipsToBounds = true
cell.pieChartView.layer.masksToBounds = true
cell.pieChartView.contentMode = .scaleAspectFit

return cell
}

对于tableViewCell:

class BVBResultsDiffAndEasyAllWordsGraphTableViewCell: UITableViewCell {

@IBOutlet weak var kanjiL: UILabel!
@IBOutlet weak var translationL: UILabel!
@IBOutlet weak var pieChartView: PieChartView!

@IBOutlet weak var plusMinusImage: UIImageView!

var testconditions: Array<String>?
var percentageSolved: Array<Int>?
var percentageNotSolved: Array<Int>?

var solvedPercentageDataEntry = PieChartDataEntry(value: 0)
var nonSolvedPercentageDataEntry = PieChartDataEntry(value: 0)

var percentageSolvedNonSolvedDataEntries = [PieChartDataEntry]()


override func awakeFromNib() {
super.awakeFromNib()

solvedPercentageDataEntry.label = NSLocalizedString("solved", comment: "piechart label for the solved area")
pieChartView.chartDescription?.text = ""
pieChartView.legend.enabled = false
pieChartView.setExtraOffsets(left: 2, top: 0, right: 2, bottom: 0)

pieChartView.holeRadiusPercent = 2.8
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state

//not used
}


func setChart(forIndexNo: Int, dataPoints: [String], valuesSolved: [Int], valuedNonSolved: [Int]){

var dataEntries: [PieChartDataEntry] = []

solvedPercentageDataEntry = PieChartDataEntry(value: Double(valuesSolved[forIndexNo]), label: "")
nonSolvedPercentageDataEntry = PieChartDataEntry(value:Double(valuedNonSolved[forIndexNo]), label: "")

dataEntries = [solvedPercentageDataEntry, nonSolvedPercentageDataEntry]

percentageSolvedNonSolvedDataEntries = [solvedPercentageDataEntry, nonSolvedPercentageDataEntry]

let pieChartDataSet = PieChartDataSet(entries: percentageSolvedNonSolvedDataEntries, label: nil)

pieChartDataSet.drawValuesEnabled = false

let pieChartData = PieChartData(dataSet: pieChartDataSet)

let colors = [UIColor.themeColor(), UIColor.red]

pieChartDataSet.colors = colors as! [NSUIColor]

pieChartView.data = pieChartData

pieChartView.notifyDataSetChanged()
}

}

最佳答案

我测试了你的代码。效果很好。还有中间那个洞,可能是配置问题。尝试添加这个

    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

希望这有帮助

关于ios - echarts(iOS图表)未显示在自定义uitableviewcell中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58789780/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com