Scrollable Graph View for iOS in Swift

, a 5-minute piece by Dev Mukherjee Dev Mukherjee

Last couple of months I have been experimenting with Swift and iOS10 with a small data visualisation project in mind. While experimenting with plotting values onto a graph, I came across Phillip McKenna's rather popular ScrollableGraphView. It's extremely simple to configure:

private func configureGraph() {
    let referenceLines = ReferenceLines()
    referenceLines.positionType = .relative
    referenceLines.relativePositions = [0, 0.5, 0.8, 0.9]
    referenceLines.referenceLineThickness = 1
    referenceLines.referenceLineLabelColor = _COLOR_PURPLE
    referenceLines.dataPointLabelColor = _COLOR_PURPLE
    referenceLines.referenceLineColor = 
        referenceLines: referenceLines)

    // Line plot
    let linePlot = LinePlot(identifier: "percentageLine")
    linePlot.fillColor = _COLOR_LIGHT_PURPLE.withAlphaComponent(0.50)
    linePlot.fillGradientType = .linear
    linePlot.lineColor = _COLOR_PURPLE
    linePlot.shouldFill = true
    linePlot.lineStyle = .smooth

    percentageGraph?.rangeMax = 100
    percentageGraph?.dataPointSpacing = 38
    percentageGraph?.topMargin = 10
    percentageGraph?.bottomMargin = 64

    percentageGraph?.addPlot(plot: linePlot)
    percentageGraph?.dataSource = self
    percentageGraph?.showsHorizontalScrollIndicator = false

There were few feature requests that had been in the queue for a while (some of which I wanted to use). We proudly sponsored some development time for APIv4. If you are in need of an iOS graphing component I highly recommend looking at this project.

Next Up: a 2-minute piece by Dev Mukherjee Dev Mukherjee

Open Sourcing for Education

Read more