https://github.com/tmdvs/coregraphicsgraph
Draw a line graph with CoreGraphics in Swift. This code is intended to be an example of how you could use CoreGraphics to draw graphs and other similar UI elements.
https://github.com/tmdvs/coregraphicsgraph
Last synced: about 1 year ago
JSON representation
Draw a line graph with CoreGraphics in Swift. This code is intended to be an example of how you could use CoreGraphics to draw graphs and other similar UI elements.
- Host: GitHub
- URL: https://github.com/tmdvs/coregraphicsgraph
- Owner: tmdvs
- License: mit
- Created: 2014-08-11T14:34:56.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2023-07-28T08:43:39.000Z (almost 3 years ago)
- Last Synced: 2025-03-27T11:50:29.476Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 53.7 KB
- Stars: 76
- Watchers: 6
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
CoreGraphicsGraph
=================

Draw a line graph with CGPath and Swift. This is really just the result of playing with Swift, and so I can't garuntee the code is production ready, or even very good.
```swift
// GraphView.swift example usage
let myData = [
["Mon" : 15],
["Tues" : 30],
["Weds" : 7],
["Thurs" : 60],
["Fri" : 30],
["Sat" : 15],
["Sun" : 45]
]
let graph = GraphView(frame: CGRect(x: 50, y: 50, width: 420, height: 200), data: myData)
self.view.addSubview(graph)
```
## Graph customisation options
There isn't really that many. The `GraphView` has a `style` property, the value of which is a `GraphStyle` struct which can be overriden.
```swift
struct GraphStyle {
struct labels {
var font = UIFont.systemFont(ofSize: 10)
var color = UIColor.black
}
struct colors {
var xAxis = UIColor.black
var yAxis = UIColor.black
var lines = UIColor.lightGray
var graph = UIColor.black
}
var colors = colors()
var labels = labels()
var showLines = true
var showPoints = true
var xMargin : CGFloat = 20
}
```