{"id":2928,"date":"2021-05-27T20:13:08","date_gmt":"2021-05-27T12:13:08","guid":{"rendered":"http:\/\/123.57.164.21\/?p=2928"},"modified":"2021-05-27T20:13:08","modified_gmt":"2021-05-27T12:13:08","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%a39%ef%bc%88%e6%8a%98%e7%ba%bf%e5%9b%be8%ef%bc%9a%e6%98%be%e7%a4%ba%e6%8c%87%e5%ae%9a%e5%8c%ba","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=2928","title":{"rendered":"Swift &#8211; \u7b2c\u4e09\u65b9\u56fe\u8868\u5e93Charts\u4f7f\u7528\u8be6\u89e39\uff08\u6298\u7ebf\u56fe8\uff1a\u663e\u793a\u6307\u5b9a\u533a\u57df\u6570\u636e\u3001\u9009\u4e2d\u5c45\u4e2d\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-102-1024x624.png\" alt=\"\" class=\"wp-image-2929\" width=\"750\" height=\"456\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-1024x624.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-300x183.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-768x468.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-1536x936.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-830x506.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-230x140.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-350x213.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102-480x292.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-102.png 1586w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/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-103-1024x559.png\" alt=\"\" class=\"wp-image-2930\" width=\"687\" height=\"374\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103-1024x559.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103-300x164.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103-830x453.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103-350x191.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103-480x262.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-103.png 1446w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/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-104-1024x637.png\" alt=\"\" class=\"wp-image-2931\" width=\"724\" height=\"450\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-1024x637.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-300x187.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-768x478.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-830x516.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-230x143.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-350x218.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104-480x298.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-104.png 1322w\" sizes=\"(max-width: 724px) 100vw, 724px\" \/><\/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-105-1024x227.png\" alt=\"\" class=\"wp-image-2932\" width=\"737\" height=\"164\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-1024x227.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-300x66.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-768x170.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-830x184.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-230x51.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-350x78.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105-480x106.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-105.png 1454w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/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    \/\/\u6298\u7ebf\u56fe\n    var chartView: LineChartView!\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u6298\u7ebf\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = LineChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 250)\n        self.view.addSubview(chartView)\n         \n        \/\/\u8bbe\u7f6e\u4ea4\u4e92\u6837\u5f0f\n        chartView.scaleXEnabled = false \/\/\u5141\u53d6\u6d88X\u8f74\u7f29\u653e\n        chartView.scaleYEnabled = false \/\/\u53d6\u6d88Y\u8f74\u7f29\u653e\n        chartView.doubleTapToZoomEnabled = false \/\/\u53cc\u51fb\u7f29\u653e\n         \n         \n        \/\/\u751f\u6210100\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [ChartDataEntry]()\n        for i in 0..&lt;100 {\n            let y = arc4random()%100\n            let entry = ChartDataEntry.init(x: Double(i), y: Double(y))\n            dataEntries.append(entry)\n        }\n        \/\/\u8fd950\u6761\u6570\u636e\u4f5c\u4e3a1\u6839\u6298\u7ebf\u91cc\u7684\u6240\u6709\u6570\u636e\n        let chartDataSet = LineChartDataSet(values: dataEntries, label: \"\u5ba2\u6d41\u91cf\uff08\u5929\uff09\")\n        \/\/\u76ee\u524d\u6298\u7ebf\u56fe\u53ea\u5305\u62ec1\u6839\u6298\u7ebf\n        let chartData = LineChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u6298\u7ebf\u56fe\u6570\u636e\n        chartView.data = chartData\n         \n        \/\/\u56fe\u8868\u6700\u591a\u663e\u793a10\u4e2a\u70b9\n       chartView.setVisibleXRangeMaximum(10)\n        \/\/\u9ed8\u8ba4\u663e\u793a\u6700\u4e00\u4e2a\u6570\u636e\n       chartView.moveViewToX(99)\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-106-1024x724.png\" alt=\"\" class=\"wp-image-2933\" width=\"704\" height=\"497\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-1024x724.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-300x212.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-768x543.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-1536x1086.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-830x587.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-230x163.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-350x247.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106-480x339.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-106.png 1562w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><\/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, ChartViewDelegate {\n     \n    \/\/\u6298\u7ebf\u56fe\n    var chartView: LineChartView!\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u6298\u7ebf\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = LineChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 250)\n        chartView.delegate = self \/\/\u8bbe\u7f6e\u4ee3\u7406\n        self.view.addSubview(chartView)\n         \n        \/\/\u8bbe\u7f6e\u4ea4\u4e92\u6837\u5f0f\n        chartView.scaleXEnabled = false \/\/\u5141\u53d6\u6d88X\u8f74\u7f29\u653e\n        chartView.scaleYEnabled = false \/\/\u53d6\u6d88Y\u8f74\u7f29\u653e\n        chartView.doubleTapToZoomEnabled = false \/\/\u53cc\u51fb\u7f29\u653e\n         \n        \/\/\u751f\u6210100\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [ChartDataEntry]()\n        for i in 0..&lt;100 {\n            let y = arc4random()%100\n            let entry = ChartDataEntry.init(x: Double(i), y: Double(y))\n            dataEntries.append(entry)\n        }\n        \/\/\u8fd950\u6761\u6570\u636e\u4f5c\u4e3a1\u6839\u6298\u7ebf\u91cc\u7684\u6240\u6709\u6570\u636e\n        let chartDataSet = LineChartDataSet(values: dataEntries, label: \"\u5ba2\u6d41\u91cf\uff08\u5929\uff09\")\n        \/\/\u76ee\u524d\u6298\u7ebf\u56fe\u53ea\u5305\u62ec1\u6839\u6298\u7ebf\n        let chartData = LineChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u6298\u7ebf\u56fe\u6570\u636e\n        chartView.data = chartData\n         \n        \/\/\u56fe\u8868\u6700\u591a\u663e\u793a10\u4e2a\u70b9\n        chartView.setVisibleXRangeMaximum(10)\n        \/\/\u9ed8\u8ba4\u663e\u793a\u6700\u4e00\u4e2a\u6570\u636e\n        chartView.moveViewToX(99)\n    }\n     \n    \/\/\u6298\u7ebf\u4e0a\u7684\u70b9\u9009\u4e2d\u56de\u8c03\n    func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry,\n                            highlight: Highlight) {\n        \/\/\u5c06\u8be5\u70b9\u5c45\u4e2d\uff08\u5176\u5b9e\u5c31\u662f\u5c06\u8be5\u70b9\u5de6\u8fb9\u7b2c5\u4e2a\u70b9\u79fb\u52a8\u9053\u56fe\u8868\u5de6\u4fa7\uff09\n        self.chartView.moveViewToAnimated(xValue: entry.x - 5, yValue: 0,\n                                          axis: .left, duration: 1)\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\/2928"}],"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=2928"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2928\/revisions"}],"predecessor-version":[{"id":2934,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2928\/revisions\/2934"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}