I want to paint a peak map in javafx, but there isn't a class to finish my aim. So I modified "LineChart" to be my "peak map", it looks that. But I want to move X axis to 0 scale(y axis), what can I do to achieve it.
By the way, if you have a better method to achieve "peak map", please give me some advices.
Thanks!
public void start(Stage stage) {
stage.setTitle("Line Chart Sample");
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("X");
yAxis.setLabel("Y");
final LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setTitle("Peak Map");
XYChart.Series<Number, Number> series1 = new XYChart.Series<>();
series1.setName("Portfolio 1");
series1.getData().add(new XYChart.Data<Number, Number>(1, 0));
series1.getData().add(new XYChart.Data<Number, Number>(1, 14));
XYChart.Series<Number, Number> series2 = new XYChart.Series<>();
series2.setName("Portfolio 2");
series2.getData().add(new XYChart.Data<Number, Number>(2, 0));
series2.getData().add(new XYChart.Data<Number, Number>(2, 34));
XYChart.Series<Number, Number> series3 = new XYChart.Series<>();
series3.setName("Portfolio 3");
series3.getData().add(new XYChart.Data<Number, Number>(3, 0));
series3.getData().add(new XYChart.Data<Number, Number>(3, 35));
XYChart.Series<Number, Number> series4 = new XYChart.Series<>();
series4.setName("Protfolio 4");
series4.getData().add(new XYChart.Data<>(2, 0));
series4.getData().add(new XYChart.Data<>(2, -8));
Scene scene = new Scene(lineChart, 800, 600);
lineChart.getData().addAll(series1, series2, series3, series4);
lineChart.setCreateSymbols(false);
lineChart.setLegendVisible(false);
stage.setScene(scene);
stage.show();
}
I played a bit with your code. Are you expecting something like this result?
Warning: it is really tricky solution.
Find a zero horizontal line object and move the
xAxis
to this position:As for me X and Y labels may be removed at all.
Note: we need handle window sizing event to move
xAxis
dynamically.