Swiftpack.co - tana90/AWLineChart as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tana90.
tana90/AWLineChart 1.1
Simple line chart
⭐️ 4
🕓 4 weeks ago
iOS
.package(url: "https://github.com/tana90/AWLineChart.git", from: "1.1")

A description of this package.

AWLineChart

Simple - lightweight line chart

How to use example


// MARK: Chart data model

struct LineChartData: AWLineChartData {
    var xValue: String
    var yValue: Double
}
    
class <#Your View Controller#>: UIViewController {

    lazy var lineChart: AWLineChart = {
        let lineChart = AWLineChart()
        lineChart.gridWidth: CGFloat = 0.3
        lineChart.lineWidth: CGFloat = 3
        lineChart.sideSpace: CGFloat = 44
        lineChart.bottomSpace: CGFloat = 44
        lineChart.showVerticalGrid: Bool = true
        lineChart.showHorizontalGrid: Bool = true
        lineChart.showBottomLabels: Bool = true
        lineChart.showSideLabels: Bool = true
        lineChart.gridColor: UIColor = .gray
        lineChart.labelsColor: UIColor = .black
        lineChart.animationDuration: Float = 0.3
        lineChart.chartType = .curved
        lineChart.tintColor = .orange
        lineChart.dataSource = self
        lineChart.delegate = self
        return lineGraph
    }()
        
    var data: [LineChartData] = [
        LineChartData(xValue: "Value 1", yValue: 0.4),
        LineChartData(xValue: "Value 2", yValue: 0.6),
        LineChartData(xValue: "Value 3", yValue: 0.7),
        LineChartData(xValue: "Value 4", yValue: 0.3),
        LineChartData(xValue: "Value 5", yValue: 0.2),
        LineChartData(xValue: "Value 6", yValue: 0.5)
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        lineChart.reloadData()
    }
}
    
// MARK: Data Source

extension <#Your View Controller#>: AWLineChartDataSource {

    func numberOfItems(in lineChart: AWLineChart) -> Int { 
        return data.count 
    }
    
    func lineChart(_ lineChart: AWLineChart, xValueAt index: Int) -> String { 
        return data[index].xValue 
    }
    
    func lineChart(_ lineChart: AWLineChart, yValueAt index: Int) -> Double { 
        return data[index].yValue 
    }
    
    func numberOfVerticalLines(in lineChart: AWLineChart) -> Int { 6 }
    
    func numberOfHorizontalLines(in lineChart: AWLineChart) -> Int { 4 }
    
    func numberOfBottomLabels(in lineChart: AWLineChart) -> Int { 6 }
    
    func numberOfSideLabels(in lineChart: AWLineChart) -> Int { 5 }
    
    func lineChart(_ lineChart: AWLineChart, verticalDashPatternAt index: Int) -> [NSNumber] { [] }
    
    func lineChart(_ lineChart: AWLineChart, horizontalDashPatternAt index: Int) -> [NSNumber] { [4.0, 18.0] }
}

// MARK: Delegate

extension <#Your View Controller#>: AWLineChartDelegate {
    
    func lineChartDidStartRender(_ lineChart: AWLineChart) {
        // Called when start rendering
    }
    
    func lineChartDidFinishRender(_ lineChart: AWLineChart) {
        // Called when finish rendering
    }
}

Requirements

  • iOS 12.0+
  • Swift 5.0+

How it looks

GitHub

link
Stars: 4
Last commit: 17 hours ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Minor refactoring
4 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics