gpt4 book ai didi

ios - danielgindi/Charts Pie Chart 精选指数

转载 作者:可可西里 更新时间:2023-11-01 06:21:25 25 4
gpt4 key购买 nike

我正在使用 Charts绘制饼图。它工作正常,但我需要将选定的部分索引传递给下一个 View Controller 。我使用了下面的代码并阅读了他们的 release notes对于图表 3.0。我在 Swift 3 中工作。在以前的版本中,选定的索引是从 entry.dataSetIndex 中获取的。

通过这段代码,我总是得到 0 索引。请提供任何帮助。

extension ViewController: ChartViewDelegate {

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {

print(highlight.dataSetIndex)
}

}

最佳答案

使用 iOS Charts 3.0.0,以下代码输出选定的索引:

class ChartController: UIViewController, ChartViewDelegate {

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {

if let dataSet = chartView.data?.dataSets[ highlight.dataSetIndex] {

let sliceIndex: Int = dataSet.entryIndex( entry: entry)
print( "Selected slice index: \( sliceIndex)")
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear( animated)

// 1. create chart view
let chart = PieChartView( frame: self.view.frame)
chart.delegate = self

// TODO: exercise for reader...add data, styles, etc.
}

关于ios - danielgindi/Charts Pie Chart 精选指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40858523/

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