I'm trying to implement a chart in JavaFX. It should:
- Initially have a linear X axis,
- When a button is pressed, change the axis to a logarithmic X axis
The problem is that LineChart does not have a setAxis method. Another problem is that my architecture is designed in such a way that I can't simply redraw the LineChart.
I tried to simply recalculate the X-axis values. But in this case the ticks are positioned incorrectly and the chart collapses horizontally.
Then I implemented my own LogarithmicAxis class, which inherits from ValueAxis<Number>. It works correctly, and if I create a lineChart like this:
NumberAxis yAxis = new NumberAxis();
LogarithmicAxis xAxis = new LogarithmicAxis();
LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
I get what I need. But I can't change the axis dynamically
My view code consists of methods like
public Region build() {
GridPane gridPane = new GridPane();
ColumnConstraints col1 = new ColumnConstraints();
gridPane.getColumnConstraints().addAll(col1);
gridPane.add(createSettingsBox(), 0, 0, 0, 0);
return gridPane;
}
private Node createSettingsBox() {
VBox settingsBox = new VBox(10);
settingsBox.getChildren().add(createButton());
return settingsBox;
}
So I get the view. But how can I reach the chart and redraw it if it has a high nesting level?