{"id":1600,"date":"2022-05-30T21:08:16","date_gmt":"2022-05-30T12:08:16","guid":{"rendered":"https:\/\/www.typea.info\/blog\/?p=1600"},"modified":"2022-05-30T21:12:43","modified_gmt":"2022-05-30T12:12:43","slug":"swift_ios_chart","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2022\/05\/30\/swift_ios_chart\/","title":{"rendered":"Swift iOS\u306b\u30c1\u30e3\u30fc\u30c8\u3092\u7d44\u307f\u8fbc\u3080"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/danielgindi\/Charts\">GitHub &#8211; danielgindi\/Charts: Beautiful charts for iOS\/tvOS\/OSX! The Apple side of the crossplatform MPAndroidChart.<\/a><\/p>\n<p>\u30b0\u30e9\u30d5\u7528\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001\u30b0\u30e9\u30d5\u3092\u8868\u793a\u3055\u305b\u308b\u3002<\/p>\n<p>XCode \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u3001Add Package \u3092\u9078\u629e\u3057\u3001\u4e0a\u8a18GiHub\u30ea\u30dd\u30b8\u30c8\u30ea\u306eURL\u3092\u30c0\u30a4\u30a2\u30ed\u30b0\u306e\u691c\u7d22\u7a93\u306b\u5165\u529b\u3002<\/p>\n<p>https:\/\/github.com\/danielgindi\/Charts.git<\/p>\n<p>Add Package\u3067\u5229\u7528\u53ef\u80fd\u306b\u306a\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/05\/char_package.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"char_package.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/05\/char_package.png\" alt=\"char_package\" width=\"600\" height=\"330\" border=\"0\" \/><\/a><\/p>\n<p>GiHub\u306e\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306b\u3042\u308b\u3001<a href=\"https:\/\/www.youtube.com\/watch?v=mWhwe_tLNE8&amp;list=PL_csAAO9PQ8bjzg-wxEff1Fr0Y5W1hrum\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u3092\u898b\u306a\u304c\u3089\u5b9f\u88c5\u3057\u3066\u3044\u304f\u3002<\/p>\n<p>TinyConstraings\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u3082\u4e0a\u8a18\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u8ffd\u52a0\u3057\u3066\u3044\u308b\u306e\u3060\u304c\u3001\u306a\u304b\u306a\u304b\u308f\u304b\u308a\u306b\u304f\u3044\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2022\/03\/26\/autolayout_concept\/\">AutoLayout<\/a>\u3092\u30b3\u30fc\u30c9\u3067\u7c21\u6f54\u306b\u8a2d\u5b9a\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u3088\u3046\u3060\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/roberthein\/TinyConstraints.git\">https:\/\/github.com\/roberthein\/TinyConstraints.git<\/a><\/p>\n<p>\u3082Charts\u540c\u69d8\u306b\u3001Add Package\u3057\u3066\u304a\u304f\u3002<\/p>\n<h2>1.\u57fa\u672c\u7684\u306a\u30b0\u30e9\u30d5<\/h2>\n<p>\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u3057\u305f\u304c\u3044\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u9069\u5f53\u306a\u30b0\u30e9\u30d5\u3092\u4f5c\u6210\u3057\u3066\u307f\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/05\/ios_graph01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"ios_graph01.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/05\/ios_graph01.png\" alt=\"ios_graph01\" width=\"258\" height=\"532\" border=\"0\" \/><\/a><\/p>\n<pre class=\"prettyprint\">import UIKit\nimport Charts\nimport TinyConstraints\n\n\/\/\n\/\/ https:\/\/www.youtube.com\/watch?v=mWhwe_tLNE8&amp;list=PL_csAAO9PQ8bjzg-wxEff1Fr0Y5W1hrum&amp;index=6\n\/\/\nclass LineChartViewController: UIViewController, ChartViewDelegate {\n        lazy var lineChartView: LineChartView = {\n        let charView = LineChartView()\n        charView.backgroundColor = .systemBlue\n        return charView\n    }()\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view.\n                view.addSubview(lineChartView)\n                lineChartView.centerInSuperview()\n        lineChartView.width(to: view)\n        lineChartView.heightToWidth(of: view)\n                setData()\n    }\n    func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {\n        print(entry)\n    }\n    func setData() {\n        let set1 = LineChartDataSet(entries: yValues, label: \"Subscribers\")\n        let data = LineChartData(dataSet: set1)\n        lineChartView.data = data\n    }\n    let yValues: [ChartDataEntry] = [\n        ChartDataEntry(x: 0.0, y: 10.0),\n        ChartDataEntry(x: 1.0, y: 12.0),\n        ChartDataEntry(x: 2.0, y: 14.0),\n        ChartDataEntry(x: 3.0, y:  9.0),\n        ChartDataEntry(x: 4.0, y:  8.0),\n        ChartDataEntry(x: 5.0, y:  7.0),\n        ChartDataEntry(x: 6.0, y: 20.0),\n        ChartDataEntry(x: 7.0, y: 22.0),\n        ChartDataEntry(x: 8.0, y: 17.0),\n        ChartDataEntry(x: 9.0, y: 16.0),\n        ChartDataEntry(x:10.0, y: 15.0)\n    ]\n}\n<\/pre>\n<h2>2.\u3044\u308d\u3044\u308d\u8a2d\u5b9a\u3092\u5f04\u308b<\/h2>\n<p>\u4e0a\u8a18\u3067\u4f5c\u6210\u3057\u305f\u30bd\u30fc\u30b9\u306b\u3001\u304a\u3082\u306bcharView\u3092\u751f\u6210\u3057\u305f\u3068\u3053\u308d\u3067\u5404\u7a2e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3001\u307e\u305f\u3001DataSet\u3068Data\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3082\u89e6\u3063\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u542b\u307f\u306e\u30b0\u30e9\u30d5\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/05\/ios_graph02.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"ios_graph02.gif\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/05\/ios_graph02.gif\" alt=\"ios_graph02\" width=\"573\" height=\"382\" border=\"0\" \/><\/a><\/p>\n<pre class=\"prettyprint\">import UIKit\nimport Charts\nimport TinyConstraints\n\n\/\/\n\/\/ https:\/\/www.youtube.com\/watch?v=mWhwe_tLNE8&amp;list=PL_csAAO9PQ8bjzg-wxEff1Fr0Y5W1hrum&amp;index=6\n\/\/\nclass LineChartViewController: UIViewController, ChartViewDelegate {\n        lazy var lineChartView: LineChartView = {\n        let charView = LineChartView()\n        charView.backgroundColor = .systemBlue\n        \/\/ Customize start\n        charView.rightAxis.enabled = false\n        let yAxis = charView.leftAxis\n        yAxis.labelFont = .boldSystemFont(ofSize: 12)\n        yAxis.setLabelCount(6, force: false)\n        yAxis.labelTextColor = .white\n        yAxis.axisLineColor = .white\n        yAxis.labelPosition = .insideChart\n        let xAxis = charView.xAxis\n        xAxis.labelPosition = .bottom\n        xAxis.labelFont = .boldSystemFont(ofSize: 12)\n        xAxis.setLabelCount(6, force: false)\n        xAxis.labelTextColor = .white\n        xAxis.axisLineColor = .systemBlue\n        charView.animate(yAxisDuration: 2.5)\n        \/\/ Customize end\n        return charView\n    }()\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view.\n                view.addSubview(lineChartView)\n                lineChartView.centerInSuperview()\n        lineChartView.width(to: view)\n        lineChartView.heightToWidth(of: view)\n                setData()\n    }\n    func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {\n        print(entry)\n    }\n    func setData() {\n        let set1 = LineChartDataSet(entries: yValues, label: \"Subscribers\")\n        \/\/ Customize start\n        set1.mode = .cubicBezier\n        set1.drawCirclesEnabled = false\n        set1.lineWidth = 3\n        set1.setColor(.white)\n        set1.fill = Fill(color: .white)\n        set1.fillAlpha = 0.8\n        set1.drawFilledEnabled = true\n        \/\/ Customize end\n        let data = LineChartData(dataSet: set1)\n        \/\/ Customize start\n        data.setDrawValues(false)\n        \/\/ Customize end\n                lineChartView.data = data\n    }\n    let yValues: [ChartDataEntry] = [\n        ChartDataEntry(x: 0.0, y: 10.0),\n        ChartDataEntry(x: 1.0, y: 12.0),\n        ChartDataEntry(x: 2.0, y: 14.0),\n        ChartDataEntry(x: 3.0, y:  9.0),\n        ChartDataEntry(x: 4.0, y:  8.0),\n        ChartDataEntry(x: 5.0, y:  7.0),\n        ChartDataEntry(x: 6.0, y: 20.0),\n        ChartDataEntry(x: 7.0, y: 22.0),\n        ChartDataEntry(x: 8.0, y: 17.0),\n        ChartDataEntry(x: 9.0, y: 16.0),\n        ChartDataEntry(x:10.0, y: 15.0)\n    ]\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GitHub &#8211; danielgindi\/Charts: Beautiful charts for iOS\/tvOS\/OSX! The Apple side of the crossplatform MPAn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1599,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[108,127,126],"tags":[173,191,187,130,129],"class_list":["post-1600","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","category-xcode","tag-autolayout","tag-chart","tag-ios","tag-swift","tag-xcode"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1600"}],"version-history":[{"count":2,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1600\/revisions"}],"predecessor-version":[{"id":1602,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1600\/revisions\/1602"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media\/1599"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}