Latest 0.2.0
License MIT
Platforms ios 10.0

CI Status


To run the example project, clone the repo, and run pod install from the Example directory first.


SwiftGraphKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SwiftGraphKit'



A GraphView is a classic UIView, you can use it on your app like other UIView.
Drawing will be depends of configuration, you can add graphs, grid, axis, …

// Sample with autolayout
let graphView = GraphView()
graphView.translatesAutoresizingMaskIntoConstraints = false


    graphView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
    graphView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
    graphView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.9),
    graphView.heightAnchor.constraint(equalTo: graphView.widthAnchor)


Now, you will see how add a Graph to GraphView. Graph is a collection of GraphPoint.
Graph draw a curve and point. On this framework, graph draw only points.
To draw a curve you can using a child of Graph like BezierGraph or BreakLineGraph.

let graph = BezierGraph()
graph.color     = .darkGray
graph.thickness = 3.0

graphView.add(graph: graph)

It’s the same logic on GraphPoint, you can use a child of this class to have a different redering.

var points = [GraphPoint]()

for x in minX..<maxX {
    let y = Float.random(in: 45..<120)
    let roundedPoint = RoundedPoint(x: CGFloat(x), y: CGFloat(y))

graph.addData(data: points)


Build Platform



DataFrame is a core concept of framework. GraphView need to be positioned as all UIView.
But inside of framework, you will not use frame, or pixel to draw, but a custom unit on x and y.
This units are configured by data frame.

let minX: CGFloat = 0
let maxX: CGFloat = 6
let dataFrame = CGRect(x: minX, y: 30, width: maxX - minX, height: 220)

You can imagine x corresponding to a day of week (0 to 6).
And you can imagine your heart rate on y (30 to 220).

Framework will convert your unit to pixel. So you can resize your graphView, graph will be animated to fit with it’s frame.

If you don’t know your minY or maxY due to you use a dataSource on GraphView, you can activate autoresize.


As you can see on some sample, you can deplace on graph by scrolling and zooming. Limit of graph is base on data area. So data frame will be contains on data area.

Build Platform

This schema present position of data area, data frame & frame.

Advanced Usage

How make an override of Graph

How make an overide of GraphPoint

How work dataSource ?

How working the framework

All objects of framework is CALayer or a subclass of this class. You will find a CADisplayLink to synchonize rendering of each graphical components. Rendering is do with 60 fps.


Charles BESSONNET, you can write me to [email protected]


SwiftGraphKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "SwiftGraphKit",
    "version": "0.2.0",
    "swift_version": "4.2",
    "summary": "SwiftGraphKit is a framework to draw scrollable graph on your app.",
    "description": "SwiftGraphKit is a framework to draw graph on your app. GraphView are scrollable and zoomable, content is automatically redraw to have amazing animation.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "[email protected]": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.0"
    "platforms": {
        "ios": "10.0"
    "source_files": "Classes/**/*"

Pin It on Pinterest

Share This