0

我想在 x 轴上创建一个仅包含 7 天的图表,我想根据它们保存的日期和时间绘制读数,但只显示天的名称。

时间格式:星期四-7:23 pm,类似于“dd - HH: MM a”

import UIKit
import Charts
import TinyConstraints

class ViewController: UIViewController,ChartViewDelegate{
 
    lazy var lineChartView: LineChartView = {
        let chartView = LineChartView()
       
        
   
       
        //X-axis
       
        chartView.xAxis.centerAxisLabelsEnabled = false
        chartView.xAxis.setLabelCount(7, force: true)//sets x axis to have 7 values
        let xAxis = lineChartView.xAxis
        chartView.xAxis.axisLineWidth = 1.5
        chartView.xAxis.drawGridLinesEnabled = false//hides x-axis grids
        
        //chartView.xAxis.valueFormatter??
 
        chartView.animate(xAxisDuration: 2.5)
        return chartView
    }()
    
    func setChartData() {
        //create a set for line 1
        let color1 = NSUIColor(red: CGFloat(140.0/255.0), green: CGFloat(170.0/255.0), blue: CGFloat(177.0/255.0), alpha: 1)
        let set1 = LineChartDataSet(entries: yValues, label: "hello")
        set1.mode = .cubicBezier //makes curves smoother
        set1.setCircleColor(color1)
        set1.circleRadius = 6
        set1.circleHoleRadius = 3
        set1.lineWidth = 3
        set1.setColor(color1)
       
        //create a line chart data
        let data1 = LineChartData(dataSet: set1)
        data1.setDrawValues(false)//hides values on markers
        //add data to lineChartView
        lineChartView.data = data1
    }
    
    
    let yValues: [ChartDataEntry] = [
    ChartDataEntry(x: 0.0, y: 10.0),
    ChartDataEntry(x: 1.0, y: 5.0),
    ChartDataEntry(x: 2.0, y: 7.0),

    ]

}

4

0 回答 0