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 8 months ago
- last active 8 months ago
Hi,
I would like to display all the hours of the day in X axis e.g 01 to 24 and I haven’t been able to achieve it yet, I tried use date delta but I couldn’t figure out how it really works, could you please share a code snippet or some example.
Thanks
- Anas Iqbal asked 11 months ago
- last active 10 months ago
Hello,
I am trying to add series to a linechart, however I seem to be unable to create a XyDataSeries in Kotlin I have tried the following:
private val linedata = XyDataSeries<Double, Double>().apply { fifoCapacity = FIFO_CAPACITY }
// like from the ECG showcase example, this gives the error
// "none of the functions can be called with the arguments called"
private val linedata2 : IXyDataSeries<Double, Double> = XyDataSeries(Double.class, Double.class)
private var linedata3 : XyDataSeries<Double, Double> = XyDataSeries(Integer.class, Double.class).build()
This seems quite straightforward but I am unable to find a solution. Can you help me?
Kind regards,
Bart
- Bart Bierling asked 3 years ago
- last active 3 years ago