{"id":2949,"date":"2021-05-27T20:24:28","date_gmt":"2021-05-27T12:24:28","guid":{"rendered":"http:\/\/123.57.164.21\/?p=2949"},"modified":"2021-05-27T20:24:28","modified_gmt":"2021-05-27T12:24:28","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%a312%ef%bc%88%e6%8a%98%e7%ba%bf%e5%9b%be11%ef%bc%9a%e8%8e%b7%e5%8f%96%e3%80%81%e4%bf%9d%e5%ad%98","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=2949","title":{"rendered":"Swift &#8211; \u7b2c\u4e09\u65b9\u56fe\u8868\u5e93Charts\u4f7f\u7528\u8be6\u89e312\uff08\u6298\u7ebf\u56fe11\uff1a\u83b7\u53d6\u3001\u4fdd\u5b58\u56fe\u7247\uff0c\u6781\u7b80\u6837\u5f0f\uff09"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/05\/image-117-1024x927.png\" alt=\"\" class=\"wp-image-2950\" width=\"-65\" height=\"-58\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-1024x927.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-300x271.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-768x695.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-830x751.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-230x208.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-350x317.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117-480x434.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-117.png 1534w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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    @IBOutlet weak var imageView: UIImageView!\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        \/\/\u751f\u621020\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [ChartDataEntry]()\n        for i in 0..&lt;20 {\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: \"\u56fe\u4f8b1\")\n        \/\/\u76ee\u524d\u6298\u7ebf\u56fe\u53ea\u5305\u62ec1\u6839\u6298\u7ebf\n        let chartData = LineChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u6298\u73b0\u56fe\u6570\u636e\n        chartView.data = chartData\n    }\n     \n    @IBAction func buttonTapped(_ sender: Any) {\n        \/\/\u83b7\u53d6\u56fe\u7247\n        let image = chartView.getChartImage(transparent: true)\n        \/\/\u5c06\u5176\u663e\u793a\u5728imageView\u4e2d\n        imageView.image = image\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-118-1024x275.png\" alt=\"\" class=\"wp-image-2951\" width=\"772\" height=\"207\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-1024x275.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-300x81.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-768x207.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-1536x413.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-830x223.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-230x62.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-350x94.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118-480x129.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-118.png 1584w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/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-119-1024x483.png\" alt=\"\" class=\"wp-image-2952\" width=\"760\" height=\"359\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-1024x483.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-300x142.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-768x362.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-1536x724.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-830x391.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-230x108.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-350x165.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119-480x226.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/05\/image-119.png 1624w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/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 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: 150)\n        chartView.legend.enabled = false\n        chartView.leftAxis.enabled = false\n        chartView.leftAxis.spaceTop = 0.4\n        chartView.leftAxis.spaceBottom = 0.4\n        chartView.rightAxis.enabled = false\n        chartView.xAxis.enabled = false\n        self.view.addSubview(chartView)\n         \n        \/\/\u6298\u7ebf\u56fe\u80cc\u666f\u8272\n        chartView.backgroundColor = UIColor(red: 89\/255, green: 199\/255, blue: 250\/255,\n                                            alpha: 1)\n         \n        \/\/\u751f\u62108\u6761\u968f\u673a\u6570\u636e\n        var dataEntries = [ChartDataEntry]()\n        for i in 0..&lt;8 {\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: \"\u674e\u5b50\u660e\")\n        chartDataSet.lineWidth = 1.75\n        chartDataSet.circleRadius = 5.0\n        chartDataSet.circleHoleRadius = 2.5\n        chartDataSet.setColor(.white)\n        chartDataSet.setCircleColor(.white)\n        chartDataSet.highlightColor = .white\n        chartDataSet.drawValuesEnabled = false\n        \/\/\u76ee\u524d\u6298\u7ebf\u56fe\u53ea\u5305\u62ec1\u6839\u6298\u7ebf\n        let chartData = LineChartData(dataSets: [chartDataSet])\n         \n        \/\/\u8bbe\u7f6e\u6298\u73b0\u56fe\u6570\u636e\n        chartView.data = chartData\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\/2949"}],"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=2949"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2949\/revisions"}],"predecessor-version":[{"id":2953,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2949\/revisions\/2953"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}