Skip to content

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.

Notifications You must be signed in to change notification settings

MadanDipika/CoreGraphicsGraph

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CoreGraphicsGraph

Example 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.

// GraphView.swift example usage

let myData = [
    ["label" : "Mon",   "value" : NSNumber(int:15)],
    ["label" : "Tues",  "value" : NSNumber(int:30)],
    ["label" : "Weds",  "value" : NSNumber(int:7)],
    ["label" : "Thurs", "value" : NSNumber(int:60)],
    ["label" : "Fri",   "value" : NSNumber(int:30)],
    ["label" : "Sat",   "value" : NSNumber(int:15)],
    ["label" : "Sun",   "value" : NSNumber(int:45)],
] as NSArray

let graph = GraphView(frame: CGRectMake(50, 50, 420, 200), data: myData)
self.view.addSubview(graph)

Graph customisation options

There isn't really that many…

  • showLines - whether or not to display lines from Y axis values
  • showPoints - whether or not to display points on the line graph
  • linesColor - The colour of Y axis lines if visible
  • xAxisColor - The colour of the X axis
  • yAxisColor - The colour of the X axis
  • graphColor - The colour of the actual line graph and points
  • labelFont - Axis label font
  • labelColor - The colour of the axis labels
  • originLabelText - Text placed origin point
  • originLabelText - The colour of originLabelText
  • xMargin - padding left of initial point and right of last point

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%