Y axis range in XYChart

enter image description here

enter image description here

I have a scaling problem with plotting XYChart: my data series have floating point values โ€‹โ€‹between 0.4 and 0.5, and when plotting on a scene I get at least a value of Y 1, so I donโ€™t see anything built.

This problem does not occur if I use a series of data with higher values โ€‹โ€‹such as> 100

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

thank

+5
source share
1 answer

As stated in the JavaDoc for the NumberAxis constructor: public NumberAxis(double lowerBound, double upperBound, double tickUnit)- you can provide the lower 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);

Refresh . Chart authoring also works for me, see the following code and screenshot. You might want to upgrade to JavaFX 2.1 or later.

    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

+5
source

All Articles