iOS 图表库:SwiftCharts

jopen 9年前

wiftCharts for iOS 是基于图层的图表库。

特性列表:
  • Bars - plain, stacked, grouped, horizontal, vertical
  • Scatter
  • Line / Multiple lines
  • Areas
  • Bubble
  • Multiple axis
  • Custom units
  • Custom views
  • Multiple labels (x axis)
  • Candlestick
  • Cubic line
  • Complex interactivity support
  • Easy extensibility

Swift 1.2, iOS 7/8

iOS 图表库:SwiftCharts iOS 图表库:SwiftCharts

let labelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFont)    let chartPoints = [(2, 2), (3, 1), (5, 9), (6, 7), (8, 10), (9, 9), (10, 15), (13, 8), (15, 20), (16, 17)].map{ChartPoint(x: ChartAxisValueInt($0.0), y: ChartAxisValueInt($0.1))}    let xValues = Array(stride(from: 2, through: 16, by: 2)).map {ChartAxisValueInt($0, labelSettings: labelSettings)}  let yValues = Array(stride(from: 0, through: 20, by: 2)).map {ChartAxisValueInt($0, labelSettings: labelSettings)}    let xModel = ChartAxisModel(axisValues: xValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings))  let yModel = ChartAxisModel(axisValues: yValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings))  let chartFrame = ExamplesDefaults.chartFrame(self.view.bounds)    let chartSettings = ExamplesDefaults.chartSettings  let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: chartSettings, chartFrame: chartFrame, xModel: xModel, yModel: yModel)  let (xAxis, yAxis, innerFrame) = (coordsSpace.xAxis, coordsSpace.yAxis, coordsSpace.chartInnerFrame)    // create layer with line  let lineModel = ChartLineModel(chartPoints: chartPoints, lineColor: UIColor(red: 0.4, green: 0.4, blue: 1, alpha: 0.2), lineWidth: 3, animDuration: 0.7, animDelay: 0)  let chartPointsLineLayer = ChartPointsLineLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, lineModels: [lineModel])    // view generator - creates circle view for each chartpoint  let circleViewGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsLayer, chart: Chart) -> UIView? in      return ChartPointCircleView(center: chartPointModel.screenLoc, size: CGSizeMake(20, 20), settings: ChartPointCircleViewSettings(animDuration: 0.5))  }  // create layer that uses the view generator  let chartPointsCircleLayer = ChartPointsViewsLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, viewGenerator: circleViewGenerator, displayDelay: 0, delayBetweenItems: 0.05)    // create layer with guidelines  var settings = ChartGuideLinesDottedLayerSettings(linesColor: UIColor.blackColor(), linesWidth: ExamplesDefaults.guidelinesWidth, axis: .XAndY)  let guidelinesLayer = ChartGuideLinesDottedLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, settings: settings)    let chart = Chart(      frame: chartFrame,      layers: [          xAxis,          yAxis,          guidelinesLayer,          chartPointsLineLayer,          chartPointsCircleLayer      ]  )    self.view.addSubview(chart.view)  self.chart = chart

项目主页:http://www.open-open.com/lib/view/home/1432716030035