//****************************************************************************** // SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved. // // Web: http://www.scichart.com // Support: support@scichart.com // Sales: sales@scichart.com // // LineChartView.swift is part of the SCICHART® Examples. Permission is hereby granted // to modify, create derivative works, distribute and publish any part of this source // code whether for commercial, private or personal use. // // The SCICHART® examples are distributed in the hope that they will be useful, but // without any warranty. It is provided "AS IS" without warranty of any kind, either // expressed or implied. //****************************************************************************** class LineChartView: SCDSingleChartViewController { override var associatedType: AnyClass { return SCIChartSurface.self } override func initExample() { 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 yAxisLeft.axisId = "yAxisMyLeft" let yAxisRight = SCINumericAxis() yAxisRight.axisAlignment = .right yAxisRight.drawMajorGridLines = false yAxisRight.drawMinorGridLines = false yAxisRight.drawMajorBands = false yAxisRight.drawMajorTicks = false yAxisRight.drawMinorTicks = false yAxisRight.drawLabels = true yAxisRight.growBy = SCIDoubleRange(min: 0.2, max: 0.05) yAxisRight.axisId = "yAxisRight" let count = 30 let xValues = SCIDoubleValues(capacity: count) let yValuesLeft = SCIDoubleValues(capacity: count) let yValuesLeftSingle = SCIDoubleValues(capacity: count) let yValuesLeftDouble = SCIDoubleValues(capacity: count) let yValuesRight = SCIDoubleValues(capacity: count) let yValuesClear = 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) let y3 = sin(x) let yCount = Double(i) xValues.add(x) yValuesLeft.add(y3) yValuesLeftSingle.add(y1) yValuesLeftDouble.add(y2) yValuesRight.add(yCount) // Any values to fit in actual visible range yValuesClear.add(1) } let dataSeriesLeft = getDataSeries(xValues: xValues, yValues: yValuesLeft) let dataSeriesLeftSingle = getDataSeries(xValues: xValues, yValues: yValuesLeftSingle) let dataSeriesLeftDouble = getDataSeries(xValues: xValues, yValues: yValuesLeftDouble) let dataSeriesRight = getDataSeries(xValues: xValues, yValues: yValuesRight) let dataSeriesClear = getDataSeries(xValues: xValues, yValues: yValuesClear) let leftSeriesCollection = SCIHorizontallyStackedColumnsCollection(collection: [ getStackedSeries(dataSeries: dataSeriesLeft, yAxisId: yAxisLeft.axisId, fillColor: .magenta), getStackedSeries(dataSeries: dataSeriesLeftSingle, yAxisId: yAxisLeft.axisId, fillColor: .yellow), getStackedSeries(dataSeries: dataSeriesLeftDouble, yAxisId: yAxisLeft.axisId, fillColor: .blue), getStackedSeries(dataSeries: dataSeriesClear, yAxisId: yAxisRight.axisId, fillColor: .clear), ]) leftSeriesCollection.yAxisId = yAxisLeft.axisId let rightSeriesCollection = SCIHorizontallyStackedColumnsCollection(collection: [ getStackedSeries(dataSeries: dataSeriesClear, yAxisId: yAxisLeft.axisId, fillColor: .clear), getStackedSeries(dataSeries: dataSeriesClear, yAxisId: yAxisLeft.axisId, fillColor: .clear), getStackedSeries(dataSeries: dataSeriesClear, yAxisId: yAxisLeft.axisId, fillColor: .clear), getStackedSeries(dataSeries: dataSeriesRight, yAxisId: yAxisRight.axisId, fillColor: .green), ]) rightSeriesCollection.yAxisId = yAxisRight.axisId SCIUpdateSuspender.usingWith(self.surface) { self.surface.xAxes.add(xAxis) self.surface.yAxes.add(yAxisLeft) self.surface.yAxes.add(yAxisRight) self.surface.renderableSeries.add(items: leftSeriesCollection, rightSeriesCollection) self.surface.chartModifiers.add(items: SCDExampleBaseViewController.createDefaultModifiers()) } } fileprivate func getStackedSeries(dataSeries: ISCIXyDataSeries, yAxisId: String, fillColor: SCIColor) -> SCIStackedColumnRenderableSeries { let rSeries = SCIStackedColumnRenderableSeries() rSeries.yAxisId = yAxisId rSeries.dataSeries = dataSeries rSeries.fillBrushStyle = SCISolidBrushStyle(color: fillColor) rSeries.strokeStyle = SCISolidPenStyle(color: fillColor, thickness: 2.0) return rSeries } fileprivate func getDataSeries(xValues: SCIDoubleValues, yValues: SCIDoubleValues) -> ISCIXyDataSeries { let dataSeries = SCIXyDataSeries(xType: .double, yType: .double) dataSeries.append(x: xValues, y: yValues) return dataSeries } }