Alberto acepsut
Alberto acepsut

Reputation: 2022

Y axis range in XYChart

enter image description here

enter image description here

I have a scaling problem with XYChart plotting: my data serie ranges in float values from 0.4 and 0.5 and when plotted on a scene I get as minimum Y value 1, so I can't see anything plotted.

This problem does not arise if I use data serie with higher values such as > 100

How can I set y axis according to data serie value used?

Thanks

Upvotes: 5

Views: 10883

Answers (1)

Sergey Grinev
Sergey Grinev

Reputation: 34498

As stated in JavaDoc for NumberAxis constructor: public NumberAxis(double lowerBound, double upperBound, double tickUnit) -- you can provide bottom and lower bounds for your axis.

    NumberAxis xAxis = new NumberAxis("X-Axis", 0d, 1d, .05);
    NumberAxis yAxis = new NumberAxis("Y-Axis", 0d, 1d, .05);
    ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
            new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
            new XYChart.Data(.1, .1),
            new XYChart.Data(.2, .2))));
    ScatterChart chart = new ScatterChart(xAxis, yAxis, data);
    root.getChildren().add(chart);

Update: Autoranging of the chart works for me as well, see next code and screenshot. You may want to upgrade to JavaFX 2.1 or newer.

    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
            new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
            new XYChart.Data(.01, .1),
            new XYChart.Data(.1, .11),
            new XYChart.Data(.12, .12),
            new XYChart.Data(.18, .15),
            new XYChart.Data(.2, .2))));
    XYChart chart = new LineChart(xAxis, yAxis, data);
    root.getChildren().add(chart);

linechart

Upvotes: 5

Related Questions