简体   繁体   中英

TornadoFX scatterchart updating

I have a scatter chart with some points in it. I want to update the position of the points when i press a button. I have the following code:

class Point(var x: Int, var y: Int)

class TestView : View("TestView") {

val points = listOf(Point(0,1),Point(1,1)).observable()

override val root = borderpane {
    center {
        scatterchart("test", NumberAxis(), NumberAxis()) {
            series("Group 1") {
                points.forEach{
                    data(it.x, it.y)
                }
            }
        }
    }

    bottom {
        button("Button") {
            action {
                points[0].x = 5
            }
        }
    }
}
}

When i press the button, nothing happens. What am I doing wrong?

When you do data(it.x, it.y) while looping over your points list, you're actually adding data to the chart. Changing the list you iterated over after the fact will not have any effect on the data points you've added earlier.

Each Series has an ObservableList<XYChart.Data<Number, Number>> called data where the actual data for the chart series is stored. You can bind to the dataProperty of a series if you want to automatically update the chart as these data points change, or alternatively you can manipulate the data list directly to get the same effect without adding binding/listeners.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM