Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Y axis range in XYChart

Tags:

javafx-2

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

like image 729
Alberto acepsut Avatar asked Apr 06 '12 09:04

Alberto acepsut


1 Answers

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

like image 169
Sergey Grinev Avatar answered Nov 03 '22 00:11

Sergey Grinev