0

I've created a Fragment to hold a BarChart and a ScrollPane - the end result will be a scrollable histogram.

I'm creating these new fragments in a seperate modal using the openModal method.

The problem that i'm having is that the BarChart doesn't seem to be updating when I call my loadData method, as shown below:

class Histogram : Fragment() {


override val root = vbox{

    hgrow = Priority.ALWAYS
    vgrow = Priority.ALWAYS

    style{
        minWidth = 1280.px
        minHeight = 180.px
    }

    hbox{
        hgrow = Priority.ALWAYS
    }


}

private val bar = ScrollBar()

private var barChart = barchart("bar", CategoryAxis(), NumberAxis()){

    barGap = 0.0
    categoryGap = -1.0

    hgrow = Priority.ALWAYS
    vgrow = Priority.ALWAYS

    style{
        minWidth = 640.px
        minHeight = 240.px
        maxHeight = 480.px

    }

    isLegendVisible = false

}

private val s = XYChart.Series<String, Number>()

init{

    root.add(barChart)
    root.add(bar)

}


fun loadData(h: AlignmentHistogram){

    s.data.add(XYChart.Data<String, Number>("asd", 2))

    barChart.title = h.rname

   /* for(i in 0..MAX_DATASET_SIZE){
        if(i > h.histogram.size){
            break
        }
        val data = XYChart.Data<String, Int>((h.firstPosition + i + 1).toString(), (h.histogram[i]))
        println(data)
        s.data.add(data)
    }*/


    s.data.add(XYChart.Data<String, Number>("asasdd", 5))

    s.name = h.rname

    barChart.data.add(s)

}

}

AlignmentHistogram is just a POJO with the data for the histogram and a few other details.

I'm calling the fragment with the following code:

    val stage = Stage()
    stage.title = "${pointer.rname} - ${selectedFile.file.name}"

    val view = Histogram()
    view.loadData(h)

    val parent = StackPane()
    stage.scene = Scene(parent, 1280.0, 360.0)

    view.openModal(StageStyle.UTILITY, Modality.NONE, false, stage, false, true)

The result of this is just an empty histogram in a new modal, despite calling barChart.data.add(s)

Any ideas? Thanks in advance!

Sam
  • 1,234
  • 3
  • 17
  • 32

1 Answers1

0

Nevermind, I solved it by passing the POJO in as the scope and putting the set-up code into the init block.

This article helped with the scope part:

Tornadofx - How to pass parameter to Fragment on every instance

Sam
  • 1,234
  • 3
  • 17
  • 32