Hi all,
I’m trying to use the metal support in a little test project.
I have following lines to enable metal:
if SCIChartSurface.isMetalSupported {
sciChartSurface.renderSurface = SCIMetalRenderSurface(frame: sciChartSurface.bounds)
} else {
sciChartSurface.renderSurface = SCIOpenGLRenderSurface(frame: sciChartSurface.bounds)
}
the surface keeps empty until I remove the
sciChartSurface.renderSurface = SCIMetalRenderSurface(frame: sciChartSurface.bounds)
line – or in other words I use OpenGL.
Then the chart will render properly. I am using an iPhoneX (not simulator).
Thank you for your support!
Wall of Code:
import UIKit
import SciChart
import SnapKit
class ViewController: UIViewController {
// MARK: - UIElements
private var sciChartSurface: SCIChartSurface!
// MARK: - Vars
private var series: SCIXyDataSeries?
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupSurface()
setupData()
renderData()
}
// MARK: - Chart
private func setupSurface() {
// Create a SCIChartSurface. This is a UIView so can be added directly to the UI
sciChartSurface = SCIChartSurface.init(frame: view.bounds)
sciChartSurface.debugWhySciChartDoesntRender = true
view.addSubview(sciChartSurface)
// Detect metal with this static property
if SCIChartSurface.isMetalSupported {
sciChartSurface.renderSurface = SCIMetalRenderSurface(frame: sciChartSurface.bounds)
} else {
sciChartSurface.renderSurface = SCIOpenGLRenderSurface(frame: sciChartSurface.bounds)
}
sciChartSurface.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
sciChartSurface.translatesAutoresizingMaskIntoConstraints = true
sciChartSurface.backgroundColor = .gray
// Create an XAxis and YAxis. This step is mandatory before creating series
let xAxis = SCICategoryNumericAxis()
setup(axis: xAxis)
sciChartSurface.xAxes.add(xAxis)
let yAxis = SCINumericAxis()
setup(axis: yAxis)
sciChartSurface.yAxes.add(yAxis)
}
private func setup(axis: SCIAxisBase) {
let axisStyle = SCIAxisStyle()
let majorPen = SCISolidPenStyle(colorCode: 0xFF393532, withThickness: 0.5)
let minorPen = SCISolidPenStyle(colorCode: 0xFF262423, withThickness: 0.5)
let textFormat = SCITextFormattingStyle()
textFormat.fontSize = 16
axisStyle.majorTickBrush = majorPen
axisStyle.majorGridLineBrush = majorPen
axisStyle.gridBandBrush = SCISolidBrushStyle(colorCode: 0xE1232120)
axisStyle.minorTickBrush = minorPen
axisStyle.minorGridLineBrush = minorPen
axisStyle.labelStyle = textFormat
axisStyle.drawMinorGridLines = true
axisStyle.drawMajorBands = true
axis.style = axisStyle
}
private func setupData() {
series = SCIXyDataSeries(xType: .int16, yType: .int16)
TestData.testData.forEach { (testData) in
let xGeneric = SCIGenericType(type: .int16, .init(int32Data: testData.x))
let yGeneric = SCIGenericType(type: .int16, .init(int32Data: testData.y))
series?.appendX(xGeneric, y: yGeneric)
}
}
private func renderData() {
let renderSeries = SCIFastColumnRenderableSeries()
renderSeries.dataSeries = series
sciChartSurface.renderableSeries.add(renderSeries)
}
}
struct TestData {
var x: Int32
var y: Int32
static let testData = [TestData(x: 2017, y: 5),
TestData(x: 2018, y: 8),
TestData(x: 2019, y: 2),
TestData(x: 2020, y: 9)]
}
- Hubert Weid asked 5 years ago
- last edited 5 years ago
-
Sorry for the strange code formatting.
- You must login to post comments
Hey!
With a different project it works fine – so I don’t know what the error was in this code but now it works fine for me.
Thank you for you help!
Regards
Benedikt
- Hubert Weid answered 5 years ago
-
Hi Benedikt, thank you for the info. If you experience this issue again please let us know and we will do our best to help. Best regards, Andrew
- You must login to post comments
Hi Benedikt,
Our iOS team has pasted your code into Swift Playgrounds (removing SnapKit as it’s an external dependency) and it shows up just fine on iPhoneX.
Can you provide a complete code sample that reproduces the problem?
Best regards,
Andrew
- Andrew Burnett-Thompson answered 5 years ago
-
Hey, I uploaded the complete project to https://uploads.mobivention.eu/a8b57cd0d05d. The Password is: SecurePW. The link is valid for four weeks. You have to replace the bundleIdentifier, signing profiles and the license key. I hope it helps. Greetings Benedikt
- You must login to post comments
Hi Benedikt,
Can you try moving the line
view.addSubview(sciChartSurface)
to the end of the setupSurface() function? After the ScIChartSurface has been initialised and all axis added.
Best regards
Andrew
- Andrew Burnett-Thompson answered 5 years ago
-
Sadly it’s still Gray with no chart.
- You must login to post comments
Please login first to submit.