图(0.1.2版)

图(0.1.2版)

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最后发布2016年6月
SPM支持SPM

kokoro维护。



Graphs

面向iOS的轻量级图表视图生成器。用Swift编写。

Graphs mock

要求

  • iOS 8.0+
  • XCode 7.3+

安装

使用

导入Graphs
import Graphs
范围 -> GraphView(柱状图)
let view = (1 ... 10).barGraph(GraphRange(min: 0, max: 11)).view(viewFrame)

数组 -> GraphView(折线图)
let view = [10, 20, 4, 8, 25, 18, 21, 24, 8, 15].lineGraph(GraphRange(min: 0, max: 30)).view(viewFrame)

字典 -> GraphView(饼图)
let view = ["a": 3, "b": 8, "c": 9, "d": 20].pieGraph().view(viewFrame)
GraphData协议 -> GraphView(饼图)
import Graphs

struct Data<T: Hashable, U: NumericType>: GraphData {
    typealias GraphDataKey = T
    typealias GraphDataValue = U

    private let _key: T
    private let _value: U

    init(key: T, value: U) {
        self._key = key
        self._value = value
    }

    var key: T { get{ return self._key } }
    var value: U { get{ return self._value } }
}

let data = [
    Data(key: "John", value: 18.9),
    Data(key: "Ken", value: 32.9),
    Data(key: "Taro", value: 15.3),
    Data(key: "Micheal", value: 22.9),
    Data(key: "Jun", value: 12.9),
    Data(key: "Hanako", value: 32.2),
    Data(key: "Kent", value: 3.8)
]

let view = data.pieGraph() { (unit, totalValue) -> String? in
    return unit.key! + "\n" + String(format: "%.0f%%", unit.value / totalValue * 100.0)
}.view(viewFrame)

更多信息

-> 读取Playgrounds

示例

$ git clone https://github.com/recruit-mtl/Graphs.git
$ cd /path/to/Graphs/GraphsExample
$ pod install

然后打开GraphsExample.xcworkspace

问题

GraphView在Interface Builder上无法工作。

Interface Builder通过ObjC运行时与代码通信。而ObjC不支持泛型。

许可协议

MIT

作者