to4dy
to4dy

Reputation: 128

JAVAFX LineChart Hide/Show lines

Is it possible to show/hide certain lines in a linechart by click on the legend or does it have to be implemented manually?

Sincerely.

Upvotes: 1

Views: 2066

Answers (1)

Thomas
Thomas

Reputation: 170

Maybe each line can be a serie, and then you can alter the select line using css. I used it to change the color of the selected data from a table view.

table.getSelectionModel()
    .selectedIndexProperty()
    .addListener((observable, oldValue, newValue) -> colorPeak(oldValue, newValue));

public void colorPeak(Number oldV, Number newV) {
    if (oldV.intValue() != -1) {
        lineChart.getData().get(oldV.intValue()).getNode().setId("serie-unselect");
    }

    if (newV.intValue() != -1) {
        lineChart.getData().get(newV.intValue()).getNode().setId("serie-select");
    }
}
#serie-unselect {
    -fx-stroke: blue; 
}

#serie-select {
    -fx-stroke: //color of the background
}

Upvotes: 1

Related Questions