 import UIKit
 import Alamofire
 import AlamofireImage
+import Charts
 
 class MineViewController: UIViewController {
     

    func segmentControlClick(sender:UISegmentedControl){
        switch sender.selectedSegmentIndex {
        case 0:
            chartView?.image = UIImage.init(named: "chartWeek")
        case 1:
            chartView?.image = UIImage.init(named: "chartMonth")
        case 2:
            chartView?.image = UIImage.init(named: "chartYear")
        default:
            chartView?.image = UIImage.init(named: "chartWeek")
        }
    }
    

            }
        }
    }
    
    func setChart(_ dataPoints: [String], values: [Double]) {
        var dataEntries: [ChartDataEntry] = []
        
        for i in 0..<dataPoints.count {
            let dataEntry = ChartDataEntry(x: Double(i), y: values[i])
            dataEntries.append(dataEntry)
        }
        
        let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "单位：人次")
        let lineChartData = LineChartData(dataSet: lineChartDataSet)
        
        lineChart.data = lineChartData
        //右下角图标描述
        lineChart.chartDescription?.text = ""
        
        //左下角图例
        //        lineChart.legend.formSize = 30
        //        lineChart.legend.form = .square
        lineChart.legend.textColor = UIColor.green
        
        //设置X轴坐标
        lineChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: dataPoints)
        lineChart.xAxis.granularity = 1.0
        lineChart.xAxis.labelPosition = .bottom
        lineChart.xAxis.drawGridLinesEnabled = false
        lineChart.xAxis.axisLineColor = UIColor.brown
        lineChart.xAxis.labelTextColor = UIColor.blue
        
        //设置Y轴坐标
        //        lineChart.rightAxis.isEnabled = false
        //不显示右侧Y轴
        lineChart.rightAxis.drawAxisLineEnabled = false
        //不显示右侧Y轴数字
        lineChart.rightAxis.enabled = false
        lineChart.leftAxis.axisLineColor = UIColor.darkGray
        lineChart.leftAxis.gridColor = UIColor.lightGray
        lineChart.leftAxis.labelTextColor = UIColor.lightGray
        
        //设置双击坐标轴是否能缩放
        lineChart.scaleXEnabled = false
        lineChart.scaleYEnabled = false
        
        //外圆
        lineChartDataSet.setCircleColor(UIColor.brown)
        //画外圆
        //        lineChartDataSet.drawCirclesEnabled = true
        //内圆
        lineChartDataSet.circleHoleColor = UIColor.blue
        //画内圆
        //        lineChartDataSet.drawCircleHoleEnabled = true
        
        //线条显示样式
        
        lineChartDataSet.colors = [UIColor.cyan]
        
        //线条上的文字
        lineChartDataSet.valueColors = [UIColor.darkGray]
        //显示
        //        lineChartDataSet.drawValuesEnabled = true
        
        //添加显示动画
        lineChart.animate(xAxisDuration: 1)
    }
    
}
