zemirco / swift-linechart

Line Chart library for iOS written in Swift
602 stars 68 forks source link
chart linechart swift

Swift LineChart

line chart demo

Usage

var lineChart = LineChart()
lineChart.addLine([3, 4, 9, 11, 13, 15])

Features

Properties

Both x and y properties are of type Coordinate. Each can be customized separately and has its own settings for labels, gridlines and axis.

Labels can be switched on and off and they can have custom values.

Grid can also be switched on/off, has a custom color and you can specify how many gridlines you'd like to show.

Axis can be switched on/off, has a property to its color and you can specify how much the axis is inset from the border of your UIView.

Animations can be customized through the Animation settings.

If you'd like to show extra dots at your data points use the Dots features.

In addition to the above mentioned features you can further customize your chart.

Methods

Add line to chart.

lineChart.addLine(data: [CGFloat])

Remove charts, areas and labels but keep axis and grid.

lineChart.clear()

Make whole UIView white again

lineChart.clearAll()

Delegates

didSelectDataPoint()

Touch event happened at or close to data point.

func didSelectDataPoint(x: CGFloat, yValues: [CGFloat]) {
  println("\(x) and \(yValues)")
}

Examples

Single line with default settings.

line chart demo

var lineChart = LineChart()
lineChart.addLine([3, 4, 9, 11, 13, 15])

Two lines without grid and dots.

two lines without grid and dots

var lineChart = LineChart()
lineChart.area = false
lineChart.x.grid.visible = false
lineChart.x.labels.visible = false
lineChart.y.grid.visible = false
lineChart.y.labels.visible = false
lineChart.dots.visible = false
lineChart.addLine([3, 4, 9, 11, 13, 15])
lineChart.addLine([5, 4, 3, 6, 6, 7])

Show x and y axis

chart with x and y axis

var lineChart = LineChart()
lineChart.area = false
lineChart.x.grid.count = 5
lineChart.y.grid.count = 5
lineChart.addLine([3, 4, 9, 11, 13, 15])
lineChart.addLine([5, 4, 3, 6, 6, 7])

License

MIT