I have a ScalaFX LineChart whose XAxis is time. The data is dynamic, being updated in an AnimationTimer. As time progresses the plot moves to the right but the plot always starts at 0, so the visible domain increases, compressing the data points.
Here is the Stage:
new Stage {
title = plotTitle
scene = new Scene(600, 600) {
val series = new XYChart.Series[Number, Number]()
series.setName(s"Simple")
val xAxis = NumberAxis("Time (s)")
val yAxis = NumberAxis("Amplitude")
val lineChart = new LineChart(xAxis, yAxis)
lineChart.setAnimated(false)
lineChart.getData.add(series)
lineChart.setCreateSymbols(false)
root = lineChart
var index = 0
val timer = AnimationTimer { time =>
series.getData.add(XYChart.Data[Number, Number](index, math.cos(index)))
if (series.getData.size > 100) series.getData.remove(0, series.getData.size() - 100)
xAxis.lowerBound.value = math.max(index - 100, 0) // this has no effect
xAxis.upperBound.value = math.max(index, 100) // this has no effect
index += 1
}
timer.start()
}
}
How do I update the lower/upper bounds of the XAxis in the AnimationTimer update? I tried setting the XAxis.lower/upperBound values during the animation update but it has no effect. I have tried other things to no avail. There are JavaFX solutions I've seen but I can't translate it to ScalaFX because there is not a one-to-one mapping of types.
