// // RadarChartViewController.swift // ChartsDemo-iOS // // Created by Jacob Christie on 2017-07-09. // Copyright © 2017 jc. All rights reserved. // #if canImport(UIKit) import UIKit #endif import Charts class RadarChartViewController: DemoBaseViewController { @IBOutlet var chartView: RadarChartView! let activities = ["Burger", "Steak", "Salad", "Pasta", "Pizza"] var originalBarBgColor: UIColor! var originalBarTintColor: UIColor! var originalBarStyle: UIBarStyle! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.title = "Radar Chart" self.options = [.toggleValues, .toggleHighlight, .toggleHighlightCircle, .toggleXLabels, .toggleYLabels, .toggleRotate, .toggleFilled, .animateX, .animateY, .animateXY, .spin, .saveToGallery, .toggleData] chartView.delegate = self chartView.chartDescription.enabled = false chartView.webLineWidth = 1 chartView.innerWebLineWidth = 1 chartView.webColor = .lightGray chartView.innerWebColor = .lightGray chartView.webAlpha = 1 let marker = RadarMarkerView.viewFromXib()! marker.chartView = chartView chartView.marker = marker let xAxis = chartView.xAxis xAxis.labelFont = .systemFont(ofSize: 9, weight: .light) xAxis.xOffset = 0 xAxis.yOffset = 0 xAxis.valueFormatter = self xAxis.labelTextColor = .white let yAxis = chartView.yAxis yAxis.labelFont = .systemFont(ofSize: 9, weight: .light) yAxis.labelCount = 5 yAxis.axisMinimum = 0 yAxis.axisMaximum = 80 yAxis.drawLabelsEnabled = false let l = chartView.legend l.horizontalAlignment = .center l.verticalAlignment = .top l.orientation = .horizontal l.drawInside = false l.font = .systemFont(ofSize: 10, weight: .light) l.xEntrySpace = 7 l.yEntrySpace = 5 l.textColor = .white // chartView.legend = l self.updateChartData() chartView.animate(xAxisDuration: 1.4, yAxisDuration: 1.4, easingOption: .easeOutBack) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) UIView.animate(withDuration: 0.15) { let navBar = self.navigationController!.navigationBar self.originalBarBgColor = navBar.barTintColor self.originalBarTintColor = navBar.tintColor self.originalBarStyle = navBar.barStyle navBar.barTintColor = self.view.backgroundColor navBar.tintColor = .white navBar.barStyle = .black } } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) UIView.animate(withDuration: 0.15) { let navBar = self.navigationController!.navigationBar navBar.barTintColor = self.originalBarBgColor navBar.tintColor = self.originalBarTintColor navBar.barStyle = self.originalBarStyle } } override func updateChartData() { if self.shouldHideData { chartView.data = nil return } self.setChartData() } func setChartData() { let mult: UInt32 = 80 let min: UInt32 = 20 let cnt = 5 let block: (Int) -> RadarChartDataEntry = { _ in return RadarChartDataEntry(value: Double(arc4random_uniform(mult) + min))} let entries1 = (0.. String { return activities[Int(value) % activities.count] } }