I have been following the tutorials and in Tutorial 3 I have come to the point where data is added to an XyDataSeries and need to know the proper way to do it in Kotlin on Android (not Java).
In MainActivity.kt I have:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
SciChartSurface.setRuntimeLicenseKey("...");
val surface = SciChartSurface(this)
val chartLayout = findViewById<View>(R.id.chart_layout) as LinearLayout
chartLayout.addView(surface)
SciChartBuilder.init(this)
val sciChartBuilder = SciChartBuilder.instance()
val xAxis = sciChartBuilder.newNumericAxis()
.withAxisTitle("X Axis Title")
.withVisibleRange(-5.0, 15.0)
.build();
val yAxis = sciChartBuilder.newNumericAxis()
.withAxisTitle("Y Axis Title")
.withVisibleRange(0.0, 100.0)
.build();
val textAnnotation = sciChartBuilder.newTextAnnotation()
.withX1(5.0)
.withY1(55.0)
.withText("Hello World!")
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
.withVerticalAnchorPoint(VerticalAnchorPoint.Center)
.withFontStyle(20f, ColorUtil.White)
.build()
val chartModifiers = sciChartBuilder.newModifierGroup()
.withPinchZoomModifier().withReceiveHandledEvents(true).build()
.withZoomPanModifier().withReceiveHandledEvents(true).build()
.build()
// App crashes at the following point
val lineData: XyDataSeries<Int, Double> = sciChartBuilder.newXyDataSeries(
Int::class.java,
Double::class.java
).build()
// I presume this is also incorrect
val scatterData: XyDataSeries<Int, Double> = sciChartBuilder.newXyDataSeries(
Int::class.java,
Double::class.java
).build()
for (i in 0..999) {
lineData.append(i, Math.sin(i * 0.1))
scatterData.append(i, Math.cos(i * 0.1))
}
val lineSeries = sciChartBuilder.newLineSeries()
.withDataSeries(lineData)
.withStrokeStyle(ColorUtil.LightBlue, 2f, true)
.build();
surface.renderableSeries.add(lineSeries);
Collections.addAll(surface.yAxes, yAxis);
Collections.addAll(surface.xAxes, xAxis);
Collections.addAll(surface.annotations, textAnnotation);
Collections.addAll(surface.chartModifiers, chartModifiers);
}
}
The app crashes at the lines “val lineData: XyDataSeries<Int, Double> = sciChartBuilder.newXyDataSeries( …”. What is wrong here?
- David Fleener asked 2 years ago
- last edited 2 years ago
- You must login to post comments
I have found a solution given someone before me has had the same problem.
https://www.scichart.com/questions/android/android-kotlin-cannot-create-var-xydataseries
- David Fleener answered 2 years ago
- last edited 2 years ago
- You must login to post comments
Please login first to submit.