// // GroupedBars.swift // SciChart POC // // Created by Hal Mueller on 3/8/21. // import UIKit import SciChart class VerticallyStackedBarsViewController: UIViewController { @IBOutlet var surface: SCIChartSurface? override func viewDidLoad() { super.viewDidLoad() SCIChartSurfaceBase.isSimulatorPerformanceWatermarkHidden = true let surface = SCIChartSurface() surface.debugWhySciChartDoesntRender = false surface.translatesAutoresizingMaskIntoConstraints = false self.view.addSubview(surface) surface.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true surface.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true surface.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true surface.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true let xAxis = SCINumericAxis() xAxis.growBy = SCIDoubleRange(min: 0.05, max: 0.05) let yAxisLeft = SCINumericAxis() yAxisLeft.growBy = SCIDoubleRange(min: 0.05, max: 0.05) yAxisLeft.axisAlignment = .left surface.xAxes.add(xAxis) surface.yAxes.add(yAxisLeft) let count = 30 let xValues = SCIDoubleValues(capacity: count) let yValuesLeftSingle = SCIDoubleValues(capacity: count) let yValuesLeftDouble = SCIDoubleValues(capacity: count) for i in 1 ... count { let x = 10.0 * Double(i) / Double(count) let y1 = sin(2 * x) let y2 = 2 * sin(2 * x) xValues.add(x) yValuesLeftSingle.add(y1) yValuesLeftDouble.add(y2) } let dataSeriesLeftSingle = SCIXyDataSeries(xType: .double, yType: .double) dataSeriesLeftSingle.append(x: xValues, y: yValuesLeftSingle) let dataSeriesLeftDouble = SCIXyDataSeries(xType: .double, yType: .double) dataSeriesLeftDouble.append(x: xValues, y: yValuesLeftDouble) let rsLeftSingle = SCIStackedColumnRenderableSeries() rsLeftSingle.dataSeries = dataSeriesLeftSingle rsLeftSingle.yAxisId = yAxisLeft.axisId rsLeftSingle.fillBrushStyle = SCISolidBrushStyle(color: UIColor.yellow) rsLeftSingle.strokeStyle = SCISolidPenStyle(color: UIColor.yellow, thickness: 2.0) let rsLeftDouble = SCIStackedColumnRenderableSeries() rsLeftDouble.dataSeries = dataSeriesLeftDouble rsLeftDouble.yAxisId = yAxisLeft.axisId rsLeftDouble.fillBrushStyle = SCISolidBrushStyle(color: UIColor.blue) rsLeftDouble.strokeStyle = SCISolidPenStyle(color: UIColor.blue, thickness: 2.0) let stacks = SCIVerticallyStackedColumnsCollection() stacks.add(rsLeftSingle) stacks.add(rsLeftDouble) surface.renderableSeries.add(stacks) let legendModifier = SCILegendModifier() surface.chartModifiers.add(legendModifier) } }