Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.55 KB | None | 0 0
  1. func generateCurveFromJSON(dataJSON: JSON) {
  2.         var points = [Double, Double]()
  3.  
  4.         for (index: String, data: JSON) in dataJSON {
  5.             points.append(data["time"].doubleValue, data["value"].doubleValue)
  6.         }
  7.  
  8.         ////////////////
  9.  
  10.         /***/let labelSettings = ChartLabelSettings(font: UIFont.systemFontOfSize(5.0))
  11.  
  12.         let chartPoints = /*points*/[(2, 2), (4, 4), (7, 1), (8, 11), (12, 3)].map{ChartPoint(x: ChartAxisValueFloat(CGFloat($0.0), labelSettings: labelSettings), y: ChartAxisValueFloat(CGFloat($0.1)))}
  13.  
  14.         let xValues = chartPoints.map{$0.x}
  15.  
  16.         let yValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 10, maxSegmentCount: 20, multiple: 2, axisValueGenerator: {ChartAxisValueFloat($0, labelSettings: labelSettings)}, addPaddingSegmentIfEdge: false)
  17.  
  18.         let xModel = ChartAxisModel(axisValues: xValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings))
  19.         let yModel = ChartAxisModel(axisValues: yValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings.defaultVertical()))
  20.         /***/let chartFrame = getChartFrame(self.view.bounds) //ExamplesDefaults.chartFrame(self.view.bounds)
  21.         let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: iPhoneChartSettings, chartFrame: chartFrame, xModel: xModel, yModel: yModel)
  22.         let (xAxis, yAxis, innerFrame) = (coordsSpace.xAxis, coordsSpace.yAxis, coordsSpace.chartInnerFrame)
  23.  
  24.         let lineModel = ChartLineModel(chartPoints: chartPoints, lineColor: UIColor.redColor(), animDuration: 1, animDelay: 0)
  25.         let chartPointsLineLayer = ChartPointsLineLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, lineModels: [lineModel])
  26.  
  27.  
  28.         let trackerLayerSettings = ChartPointsLineTrackerLayerSettings(thumbSize: 20, thumbCornerRadius: 10, thumbBorderWidth: 2, infoViewFont: UIFont.systemFontOfSize(16), infoViewSize: CGSizeMake(160, 40), infoViewCornerRadius: 15)
  29.         let chartPointsTrackerLayer = ChartPointsLineTrackerLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, lineColor: UIColor.blackColor(), animDuration: 1, animDelay: 2, settings: trackerLayerSettings)
  30.  
  31.         var settings = ChartGuideLinesDottedLayerSettings(linesColor: UIColor.blackColor(), linesWidth: 0.1)
  32.         let guidelinesLayer = ChartGuideLinesDottedLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, settings: settings)
  33.  
  34.         let chart = Chart(
  35.             frame: chartFrame,
  36.             layers: [
  37.                 xAxis,
  38.                 yAxis,
  39.                 guidelinesLayer,
  40.                 chartPointsLineLayer,
  41.                 chartPointsTrackerLayer
  42.             ]
  43.         )
  44.  
  45.         self.view.addSubview(chart.view)
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement