{"id":2976,"date":"2021-05-27T20:37:01","date_gmt":"2021-05-27T12:37:01","guid":{"rendered":"http:\/\/123.57.164.21\/?p=2976"},"modified":"2021-05-27T20:37:01","modified_gmt":"2021-05-27T12:37:01","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%a315%ef%bc%88%e6%9f%b1%e7%8a%b6%e5%9b%be2%ef%bc%9a%e6%ad%a3%e8%b4%9f%e6%9f%b1%e7%8a%b6%e5%9b%be","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=2976","title":{"rendered":"Swift &#8211; \u7b2c\u4e09\u65b9\u56fe\u8868\u5e93Charts\u4f7f\u7528\u8be6\u89e315\uff08\u67f1\u72b6\u56fe2\uff1a\u6b63\u8d1f\u67f1\u72b6\u56fe\u3001\u6a2a\u5411\u6761\u5f62\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-137-1024x734.png\" alt=\"\" class=\"wp-image-2977\" width=\"718\" height=\"515\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-1024x734.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-300x215.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-768x551.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-1536x1101.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-830x595.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-230x165.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-350x251.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137-480x344.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-137.png 1576w\" sizes=\"(max-width: 718px) 100vw, 718px\" \/><\/figure><\/div>\n\n\n\n<p>2\uff0c\u6837\u4f8b\u4ee3\u7801<\/p>\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    \/\/\u67f1\u72b6\u56fe\u56fe\n    var chartView: BarChartView!\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u6298\u7ebf\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = BarChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 260)\n        self.view.addSubview(chartView)\n         \n        \/\/\u751f\u621010\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [BarChartDataEntry]()\n        for i in 0..&lt;10 {\n            let y = Double(arc4random() % 100) - 50\n            let entry = BarChartDataEntry(x: Double(i), y: y)\n            dataEntries.append(entry)\n        }\n         \n        \/\/\u6839\u636e\u6b63\u8d1f\u503c\u751f\u6210\u6bcf\u4e2a\u7acb\u67f1\u4f7f\u7528\u7684\u989c\u8272\n        let red = UIColor(red: 211\/255, green: 74\/255, blue: 88\/255, alpha: 1)\n        let green = UIColor(red: 110\/255, green: 190\/255, blue: 102\/255, alpha: 1)\n        let colors = dataEntries.map { (entry) -> NSUIColor in\n            return entry.y > 0 ? green : red\n        }\n         \n        \/\/\u8fd910\u6761\u6570\u636e\u4f5c\u4e3a\u67f1\u72b6\u56fe\u7684\u6240\u6709\u6570\u636e\n        let chartDataSet = BarChartDataSet(values: dataEntries, label: \"\u56fe\u4f8b1\")\n        \/\/\u8bbe\u7f6e\u989c\u8272\n        chartDataSet.colors = colors\n        \/\/\u76ee\u524d\u67f1\u72b6\u56fe\u53ea\u5305\u62ec1\u7ec4\u7acb\u67f1\n        let chartData = BarChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u67f1\u72b6\u56fe\u6570\u636e\n        chartView.data = chartData\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-138-1024x643.png\" alt=\"\" class=\"wp-image-2978\" width=\"751\" height=\"471\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-1024x643.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-300x188.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-768x482.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-1536x964.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-830x521.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-230x144.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-350x220.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138-480x301.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-138.png 1584w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/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    \/\/\u6a2a\u5411\u67f1\u72b6\u56fe\n    var chartView: HorizontalBarChartView!\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u67f1\u72b6\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = HorizontalBarChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 260)\n        self.view.addSubview(chartView)\n         \n        \/\/\u4e0d\u663e\u793a\u56fe\u4f8b\n        chartView.legend.enabled = false\n        \/\/x\u8f74\u663e\u793a\u5728\u5de6\u4fa7\n        chartView.xAxis.labelPosition = .bottom\n        \/\/y\u8f74\u8d77\u59cb\u523b\u5ea6\u4e3a0\n        chartView.leftAxis.axisMinimum = 0\n        chartView.rightAxis.axisMinimum = 0\n         \n        \/\/\u751f\u621010\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [BarChartDataEntry]()\n        for i in 0..&lt;10 {\n            let y = arc4random()%100\n            let entry = BarChartDataEntry(x: Double(i), y: Double(y))\n            dataEntries.append(entry)\n        }\n        \/\/\u8fd910\u6761\u6570\u636e\u4f5c\u4e3a\u67f1\u72b6\u56fe\u7684\u6240\u6709\u6570\u636e\n        let chartDataSet = BarChartDataSet(values: dataEntries, label: \"\u56fe\u4f8b1\")\n        \/\/\u76ee\u524d\u67f1\u72b6\u56fe\u53ea\u5305\u62ec1\u7ec4\u7acb\u67f1\n        let chartData = BarChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u67f1\u72b6\u56fe\u6570\u636e\n        chartView.data = chartData\n        chartView.fitScreen()\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-139-1024x565.png\" alt=\"\" class=\"wp-image-2980\" width=\"722\" height=\"398\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-1024x565.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-300x165.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-768x424.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-1536x847.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-830x458.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-230x127.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-350x193.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139-480x265.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-139.png 1574w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><\/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    \/\/\u6a2a\u5411\u67f1\u72b6\u56fe\n    var chartView: HorizontalBarChartView!\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u67f1\u72b6\u56fe\u7ec4\u4ef6\u5bf9\u8c61\n        chartView = HorizontalBarChartView()\n        chartView.frame = CGRect(x: 20, y: 80, width: self.view.bounds.width - 40,\n                                 height: 260)\n        self.view.addSubview(chartView)\n         \n        \/\/\u4e0d\u663e\u793a\u56fe\u4f8b\n        chartView.legend.enabled = false\n        \/\/x\u8f74\u663e\u793a\u5728\u5de6\u4fa7\n        chartView.xAxis.labelPosition = .bottom\n         \n        \/\/\u751f\u621010\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [BarChartDataEntry]()\n        for i in 0..&lt;10 {\n            let y = Double(arc4random() % 100) - 50\n            let entry = BarChartDataEntry(x: Double(i), y: y)\n            dataEntries.append(entry)\n        }\n         \n        \/\/\u6839\u636e\u6b63\u8d1f\u503c\u751f\u6210\u6bcf\u4e2a\u7acb\u67f1\u4f7f\u7528\u7684\u989c\u8272\n        let red = UIColor(red: 211\/255, green: 74\/255, blue: 88\/255, alpha: 1)\n        let green = UIColor(red: 110\/255, green: 190\/255, blue: 102\/255, alpha: 1)\n        let colors = dataEntries.map { (entry) -> NSUIColor in\n            return entry.y > 0 ? green : red\n        }\n         \n        \/\/\u8fd910\u6761\u6570\u636e\u4f5c\u4e3a\u67f1\u72b6\u56fe\u7684\u6240\u6709\u6570\u636e\n        let chartDataSet = BarChartDataSet(values: dataEntries, label: \"\u56fe\u4f8b1\")\n        \/\/\u8bbe\u7f6e\u989c\u8272\n        chartDataSet.colors = colors\n        \/\/\u76ee\u524d\u67f1\u72b6\u56fe\u53ea\u5305\u62ec1\u7ec4\u7acb\u67f1\n        let chartData = BarChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u67f1\u72b6\u56fe\u6570\u636e\n        chartView.data = chartData\n        chartView.fitScreen()\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2\uff0c\u6837\u4f8b\u4ee3\u7801<\/p>\n","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\/2976"}],"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=2976"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2976\/revisions"}],"predecessor-version":[{"id":2981,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2976\/revisions\/2981"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}