Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func generateCurveFromJSON(dataJSON: JSON) {
- var points = [Double, Double]()
- for (index: String, data: JSON) in dataJSON {
- points.append(data["time"].doubleValue, data["value"].doubleValue)
- }
- ////////////////
- /***/let labelSettings = ChartLabelSettings(font: UIFont.systemFontOfSize(5.0))
- 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)))}
- let xValues = chartPoints.map{$0.x}
- let yValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 10, maxSegmentCount: 20, multiple: 2, axisValueGenerator: {ChartAxisValueFloat($0, labelSettings: labelSettings)}, addPaddingSegmentIfEdge: false)
- let xModel = ChartAxisModel(axisValues: xValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings))
- let yModel = ChartAxisModel(axisValues: yValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings.defaultVertical()))
- /***/let chartFrame = getChartFrame(self.view.bounds) //ExamplesDefaults.chartFrame(self.view.bounds)
- let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: iPhoneChartSettings, chartFrame: chartFrame, xModel: xModel, yModel: yModel)
- let (xAxis, yAxis, innerFrame) = (coordsSpace.xAxis, coordsSpace.yAxis, coordsSpace.chartInnerFrame)
- let lineModel = ChartLineModel(chartPoints: chartPoints, lineColor: UIColor.redColor(), animDuration: 1, animDelay: 0)
- let chartPointsLineLayer = ChartPointsLineLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, lineModels: [lineModel])
- let trackerLayerSettings = ChartPointsLineTrackerLayerSettings(thumbSize: 20, thumbCornerRadius: 10, thumbBorderWidth: 2, infoViewFont: UIFont.systemFontOfSize(16), infoViewSize: CGSizeMake(160, 40), infoViewCornerRadius: 15)
- let chartPointsTrackerLayer = ChartPointsLineTrackerLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, lineColor: UIColor.blackColor(), animDuration: 1, animDelay: 2, settings: trackerLayerSettings)
- var settings = ChartGuideLinesDottedLayerSettings(linesColor: UIColor.blackColor(), linesWidth: 0.1)
- let guidelinesLayer = ChartGuideLinesDottedLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, settings: settings)
- let chart = Chart(
- frame: chartFrame,
- layers: [
- xAxis,
- yAxis,
- guidelinesLayer,
- chartPointsLineLayer,
- chartPointsTrackerLayer
- ]
- )
- self.view.addSubview(chart.view)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement