首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Research Kit构建饼图

如何使用Research Kit构建饼图
EN

Stack Overflow用户
提问于 2017-07-12 17:28:38
回答 1查看 230关注 0票数 2

嗨,我是swift的新手,我试着使用研究工具包应用程序来构建一个拼图。

我写了一些参考这个link的代码

当运行我的代码时,它显示错误‘类型'ViewController’不符合协议'ORK PieChartView数据源‘’

请建议如何解决此问题。

下面是我的代码:

代码语言:javascript
复制
import UIKit
    import ResearchKit

    class ViewController: UIViewController,ORKPieChartViewDataSource {


        @IBOutlet weak var pieChartView: ORKPieChartView!
        var colors : NSArray!

        override func viewDidLoad() {
            super.viewDidLoad()

                colors = [
                UIColor(red: 217/225, green: 217/255, blue: 217/225, alpha: 1),
                UIColor(red: 142/255, green: 142/255, blue: 147/255, alpha: 1),
                UIColor(red: 244/255, green: 200/255, blue: 74/255, alpha: 1)
            ]

            // Connect the pie chart object to a data source
            pieChartView.dataSource = pieChartDataSource

            // Optional custom configuration
            pieChartView.showsTitleAboveChart = false
            pieChartView.showsPercentageLabels = true
            pieChartView.drawsClockwise = true
            pieChartView.titleColor = UIColor.purple
            pieChartView.textColor = UIColor.purple
            pieChartView.title = "Weekly"
            pieChartView.text = "Report"
            pieChartView.lineWidth = 10
            pieChartView.showsPercentageLabels = true

        }

        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }

        func numberOfSegmentsInPieChartView(pieChartView: ORKPieChartView ) -> Int {
            return 3
        }

        func pieChartView(_ pieChartView: ORKPieChartView, valueForSegmentAt index: Int) -> CGFloat {
            switch index {
            case 0:
                return 60.0
            case 1:
                return 25.0
            case 2:
                return 15.0
            }

            // Optional methods
            // Give a color to each segment in the pie chart.
            func pieChartView(pieChartView: ORKPieChartView, colorForSegmentAtIndex index: Int) -> UIColor {
                return colors[index]
            }

            // Give a title to each segment in the pie chart.
            func pieChartView(pieChartView: ORKPieChartView, titleForSegmentAtIndex index: Int) -> String {
                switch index {
                case 0:
                    return "Steps taken"
                case 1:
                    return "Tasks completed"
                case 2:
                    return "Surveys completed"
                default:
                    return "task \(index + 1)"
                }
            }
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2017-07-12 18:11:12

错误‘类型'ViewController’不符合协议'ORK PieChartView DataSource‘means that you are not implemented all the required data source methods.....在您的代码中,您以func pieChartView(_ pieChartView: ORKPieChartView, valueForSegmentAt index: Int) -> CGFloat的形式编写了一个wrong datasource method,如下所示进行更改.....

代码语言:javascript
复制
func pieChartView(pieChartView: ORKPieChartView, valueForSegmentAt index: Int) -> CGFloat {
                switch index {
                case 0:
                    return 60.0
                case 1:
                    return 25.0
                case 2:
                    return 15.0
                }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45053763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档