{"id":3049,"date":"2021-05-27T21:43:27","date_gmt":"2021-05-27T13:43:27","guid":{"rendered":"http:\/\/123.57.164.21\/?p=3049"},"modified":"2021-05-27T21:43:27","modified_gmt":"2021-05-27T13:43:27","slug":"swift-%e7%ac%ac%e4%b8%89%e6%96%b9%e5%9b%be%e8%a1%a8%e5%ba%93charts%e4%bd%bf%e7%94%a8%e8%af%a6%e8%a7%a323%ef%bc%88%e9%9b%b7%e8%be%be%e5%9b%be%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=3049","title":{"rendered":"Swift &#8211; \u7b2c\u4e09\u65b9\u56fe\u8868\u5e93Charts\u4f7f\u7528\u8be6\u89e323\uff08\u96f7\u8fbe\u56fe\uff09"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-193-1024x614.png\" alt=\"\" class=\"wp-image-3050\" width=\"702\" height=\"420\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-1024x614.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-300x180.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-768x460.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-830x498.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-230x138.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-350x210.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193-480x288.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-193.png 1408w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport Charts\n \nclass ViewController: UIViewController {\n     \n    \/\/\u96f7\u8fbe\u56fe\n    var chartView: RadarChartView!\n     \n    \/\/\u96f7\u8fbe\u56fe\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u6807\u7b7e\u6587\u5b57\n    let activities = [\"\u529b\u91cf\", \"\u654f\u6377\", \"\u751f\u547d\", \"\u667a\u529b\", \"\u9b54\u6cd5\", \"\u5e78\u8fd0\"]\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u6298\u7ebf\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = RadarChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 260)\n        self.view.addSubview(chartView)\n         \n        \/\/\u7ef4\u5ea6\u6807\u7b7e\u6587\u5b57\n        chartView.xAxis.valueFormatter = self\n         \n        \/\/\u6700\u5c0f\u3001\u6700\u5927\u523b\u5ea6\u503c\n        let yAxis = chartView.yAxis\n        yAxis.axisMinimum = 0\n        yAxis.axisMaximum = 100\n        yAxis.labelCount = 4\n        yAxis.drawLabelsEnabled = false \/\/\u4e0d\u663e\u793a\u523b\u5ea6\u503c\n         \n        \/\/\u751f\u62106\u6761\u968f\u673a\u6570\u636e\n        let dataEntries = (0..&lt;6).map { (i) -> RadarChartDataEntry in\n            return RadarChartDataEntry(value: Double(arc4random_uniform(50) + 50))\n        }\n        let chartDataSet = RadarChartDataSet(values: dataEntries, label: \"\u674e\u5927\u5b9d\")\n        \/\/\u76ee\u524d\u96f7\u8fbe\u56fe\u53ea\u5305\u62ec1\u7ec4\u6570\u636e\n        let chartData = RadarChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u96f7\u8fbe\u56fe\u6570\u636e\n        chartView.data = chartData\n    }\n}\n \nextension ViewController: IAxisValueFormatter {\n    \/\/\u7ef4\u5ea6\u6807\u7b7e\u6587\u5b57\uff08x\u8f74\u6587\u5b57\uff09\n    func stringForValue(_ value: Double, axis: AxisBase?) -> String {\n        return activities[Int(value) % activities.count]\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-194-1024x540.png\" alt=\"\" class=\"wp-image-3051\" width=\"729\" height=\"383\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-1024x540.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-300x158.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-768x405.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-830x437.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-230x121.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-350x184.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194-480x253.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-194.png 1480w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport Charts\n \nclass ViewController: UIViewController {\n     \n    \/\/\u96f7\u8fbe\u56fe\n    var chartView: RadarChartView!\n     \n    \/\/\u96f7\u8fbe\u56fe\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u6807\u7b7e\u6587\u5b57\n    let activities = [\"\u529b\u91cf\", \"\u654f\u6377\", \"\u751f\u547d\", \"\u667a\u529b\", \"\u9b54\u6cd5\", \"\u5e78\u8fd0\"]\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u6298\u7ebf\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = RadarChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 260)\n        self.view.addSubview(chartView)\n         \n        \/\/\u7ef4\u5ea6\u6807\u7b7e\u6587\u5b57\n        chartView.xAxis.valueFormatter = self\n         \n        \/\/\u6700\u5c0f\u3001\u6700\u5927\u523b\u5ea6\u503c\n        let yAxis = chartView.yAxis\n        yAxis.axisMinimum = 0\n        yAxis.axisMaximum = 100\n        yAxis.labelCount = 4\n        yAxis.drawLabelsEnabled = false \/\/\u4e0d\u663e\u793a\u523b\u5ea6\u503c\n         \n        \/\/\u968f\u673a\u6570\u636e\u751f\u6210\u65b9\u6cd5\n        let block: (Int) -> RadarChartDataEntry = { _ in\n            return RadarChartDataEntry(value: Double(arc4random_uniform(50) + 50))\n        }\n        \/\/\u751f\u6210\u4e24\u7ec4\u6570\u636e\n        let dataEntries1 = (0..&lt;6).map(block)\n        let chartDataSet1 = RadarChartDataSet(values: dataEntries1, label: \"\u674e\u5927\u5b9d\")\n        chartDataSet1.setColor(ChartColorTemplates.joyful()[4])\n         \n        let dataEntries2 = (0..&lt;6).map(block)\n        let chartDataSet2 = RadarChartDataSet(values: dataEntries2, label: \"\u738b\u5c0f\u5f3a\")\n        chartDataSet1.setColor(ChartColorTemplates.joyful()[1])\n         \n        \/\/\u76ee\u524d\u96f7\u8fbe\u56fe\u5305\u62ec2\u7ec4\u6570\u636e\n        let chartData = RadarChartData(dataSets: [chartDataSet1, chartDataSet2])\n        chartData.setDrawValues(false) \/\/\u4e0d\u663e\u793a\u503c\u6807\u7b7e\n         \n        \/\/\u8bbe\u7f6e\u96f7\u8fbe\u56fe\u6570\u636e\n        chartView.data = chartData\n    }\n}\n \nextension ViewController: IAxisValueFormatter {\n    \/\/\u7ef4\u5ea6\u6807\u7b7e\u6587\u5b57\uff08x\u8f74\u6587\u5b57\uff09\n    func stringForValue(_ value: Double, axis: AxisBase?) -> String {\n        return activities[Int(value) % activities.count]\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-196-1024x641.png\" alt=\"\" class=\"wp-image-3053\" width=\"793\" height=\"496\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-1024x641.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-300x188.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-768x481.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-1536x962.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-830x520.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-230x144.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-350x219.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196-480x301.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-196.png 1648w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-197-1024x650.png\" alt=\"\" class=\"wp-image-3054\" width=\"711\" height=\"451\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-1024x650.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-300x190.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-768x488.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-1536x975.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-830x527.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-230x146.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-350x222.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197-480x305.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-197.png 1610w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-198-1024x583.png\" alt=\"\" class=\"wp-image-3055\" width=\"731\" height=\"416\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-1024x583.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-300x171.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-768x437.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-1536x874.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-830x472.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-230x131.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-350x199.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198-480x273.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-198.png 1638w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-200-1024x581.png\" alt=\"\" class=\"wp-image-3057\" width=\"862\" height=\"488\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-1024x581.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-300x170.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-768x436.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-1536x871.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-830x471.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-230x130.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-350x198.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200-480x272.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-200.png 1700w\" sizes=\"(max-width: 862px) 100vw, 862px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-201-1024x535.png\" alt=\"\" class=\"wp-image-3058\" width=\"809\" height=\"422\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-1024x535.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-300x157.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-768x401.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-830x434.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-230x120.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-350x183.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201-480x251.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-201.png 1520w\" sizes=\"(max-width: 809px) 100vw, 809px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport Charts\n \nclass ViewController: UIViewController {\n     \n    \/\/\u96f7\u8fbe\u56fe\n    var chartView: RadarChartView!\n     \n    \/\/\u96f7\u8fbe\u56fe\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u6807\u7b7e\u6587\u5b57\n    let activities = [\"\u529b\u91cf\", \"\u654f\u6377\", \"\u751f\u547d\", \"\u667a\u529b\", \"\u9b54\u6cd5\", \"\u5e78\u8fd0\"]\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u8bbe\u7f6e\u9875\u9762\u80cc\u666f\u8272\n        self.view.backgroundColor = UIColor(red: 0x3C\/255, green: 0x41\/255,\n                                            blue: 0x52\/255, alpha: 1)\n         \n        \/\/\u521b\u5efa\u6298\u7ebf\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = RadarChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 260)\n        self.view.addSubview(chartView)\n        \/\/\u4fee\u6539\u7f51\u683c\u6837\u5f0f\n        chartView.webLineWidth = 1\n        chartView.innerWebLineWidth = 1\n        chartView.webColor = .lightGray\n        chartView.innerWebColor = .lightGray\n        chartView.webAlpha = 1\n         \n        \/\/\u7ef4\u5ea6\u6807\u7b7e\u6587\u5b57\n        let xAxis = chartView.xAxis\n        xAxis.valueFormatter = self\n        xAxis.labelTextColor = .white\n         \n        \/\/\u6700\u5c0f\u3001\u6700\u5927\u523b\u5ea6\u503c\n        let yAxis = chartView.yAxis\n        yAxis.axisMinimum = 0\n        yAxis.axisMaximum = 100\n        yAxis.labelCount = 4\n        yAxis.drawLabelsEnabled = false \/\/\u4e0d\u663e\u793a\u523b\u5ea6\u503c\n        yAxis.labelTextColor = .white\n         \n        \/\/\u56fe\u4f8b\u6837\u5f0f\n        let l = chartView.legend\n        l.textColor = .white\n         \n        \/\/\u751f\u62106\u6761\u968f\u673a\u6570\u636e\n        let dataEntries = (0..&lt;6).map { (i) -> RadarChartDataEntry in\n            return RadarChartDataEntry(value: Double(arc4random_uniform(50) + 50))\n        }\n        let chartDataSet = RadarChartDataSet(values: dataEntries, label: \"\u674e\u5927\u5b9d\")\n        chartDataSet.setColor(UIColor(red: 121\/255, green: 162\/255,\n                                      blue: 175\/255, alpha: 1))\n        chartDataSet.fillColor = UIColor(red: 121\/255, green: 162\/255,\n                                         blue: 175\/255, alpha: 1)\n        chartDataSet.drawFilledEnabled = true\n        chartDataSet.fillAlpha = 0.7\n        chartDataSet.lineWidth = 2\n        chartDataSet.drawHighlightCircleEnabled = true \/\/\u9009\u4e2d\u540e\u663e\u793a\u5706\u5708\n        chartDataSet.setDrawHighlightIndicators(false) \/\/\u9009\u4e2d\u540e\u4e0d\u663e\u793a\u5341\u5b57\u7ebf\n         \n        \/\/\u76ee\u524d\u96f7\u8fbe\u56fe\u53ea\u5305\u62ec1\u7ec4\u6570\u636e\n        let chartData = RadarChartData(dataSets: [chartDataSet])\n        chartData.setValueFont(.systemFont(ofSize: 8, weight: .light))\n        chartData.setValueTextColor(.white)\n         \n        \/\/\u8bbe\u7f6e\u96f7\u8fbe\u56fe\u6570\u636e\n        chartView.data = chartData\n    }\n}\n \nextension ViewController: IAxisValueFormatter {\n    \/\/\u7ef4\u5ea6\u6807\u7b7e\u6587\u5b57\uff08x\u8f74\u6587\u5b57\uff09\n    func stringForValue(_ value: Double, axis: AxisBase?) -> String {\n        return activities[Int(value) % activities.count]\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3049"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3049"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3049\/revisions"}],"predecessor-version":[{"id":3059,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3049\/revisions\/3059"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}