The calculation of dataMaxValue and dataMinValue should ignore values which are Double.NaN or null.
This would allow to use auto-ranging even if these values are present.
A more "generic" issue regarding NaN and null as values in series is: https://javafx-jira.kenai.com/browse/RT-38203
The following example leads to a working Application but the auto-ranging does not work.
If the bounds of the y-axis are set manually the chart looks fine (except the printing of the line [other issue]).
====================================
Example Use-Case with bad y-axis auto-ranging:
====================================
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;
public class Test extends Application {
@SuppressWarnings("unchecked")
@Override
public void start(Stage stage) throws Exception {
Data<Number, Number> element1 = new Data<Number, Number>(1, 1);
Data<Number, Number> element2 = new Data<Number, Number>(2, Double.NaN);
Data<Number, Number> element3 = new Data<Number, Number>(3, 3);
Data<Number, Number> element4 = new Data<Number, Number>(4, 4);
ObservableList<Data<Number, Number>> dataList = FXCollections.observableArrayList(element1, element2, element3, element4);
Series<Number, Number> series = new Series<>(dataList);
ObservableList<Series<Number, Number>> seriesList = FXCollections.observableArrayList(series);
LineChart<Number, Number> root = new LineChart<Number, Number>(new NumberAxis(), new NumberAxis(), seriesList);
stage.setScene(new Scene(root));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
====================================
Alternative with manual y-axis ranging:
====================================
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;
public class Test extends Application {
@SuppressWarnings("unchecked")
@Override
public void start(Stage stage) throws Exception {
Data<Number, Number> element1 = new Data<Number, Number>(1, 1);
Data<Number, Number> element2 = new Data<Number, Number>(2, Double.NaN);
Data<Number, Number> element3 = new Data<Number, Number>(3, 3);
Data<Number, Number> element4 = new Data<Number, Number>(4, 4);
ObservableList<Data<Number, Number>> dataList = FXCollections.observableArrayList(element1, element2, element3, element4);
Series<Number, Number> series = new Series<>(dataList);
ObservableList<Series<Number, Number>> seriesList = FXCollections.observableArrayList(series);
NumberAxis yAxis = new NumberAxis();
yAxis.setAutoRanging(false);
yAxis.setLowerBound(1);
yAxis.setUpperBound(4);
LineChart<Number, Number> root = new LineChart<Number, Number>(new NumberAxis(), yAxis, seriesList);
stage.setScene(new Scene(root));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This would allow to use auto-ranging even if these values are present.
A more "generic" issue regarding NaN and null as values in series is: https://javafx-jira.kenai.com/browse/RT-38203
The following example leads to a working Application but the auto-ranging does not work.
If the bounds of the y-axis are set manually the chart looks fine (except the printing of the line [other issue]).
====================================
Example Use-Case with bad y-axis auto-ranging:
====================================
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;
public class Test extends Application {
@SuppressWarnings("unchecked")
@Override
public void start(Stage stage) throws Exception {
Data<Number, Number> element1 = new Data<Number, Number>(1, 1);
Data<Number, Number> element2 = new Data<Number, Number>(2, Double.NaN);
Data<Number, Number> element3 = new Data<Number, Number>(3, 3);
Data<Number, Number> element4 = new Data<Number, Number>(4, 4);
ObservableList<Data<Number, Number>> dataList = FXCollections.observableArrayList(element1, element2, element3, element4);
Series<Number, Number> series = new Series<>(dataList);
ObservableList<Series<Number, Number>> seriesList = FXCollections.observableArrayList(series);
LineChart<Number, Number> root = new LineChart<Number, Number>(new NumberAxis(), new NumberAxis(), seriesList);
stage.setScene(new Scene(root));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
====================================
Alternative with manual y-axis ranging:
====================================
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;
public class Test extends Application {
@SuppressWarnings("unchecked")
@Override
public void start(Stage stage) throws Exception {
Data<Number, Number> element1 = new Data<Number, Number>(1, 1);
Data<Number, Number> element2 = new Data<Number, Number>(2, Double.NaN);
Data<Number, Number> element3 = new Data<Number, Number>(3, 3);
Data<Number, Number> element4 = new Data<Number, Number>(4, 4);
ObservableList<Data<Number, Number>> dataList = FXCollections.observableArrayList(element1, element2, element3, element4);
Series<Number, Number> series = new Series<>(dataList);
ObservableList<Series<Number, Number>> seriesList = FXCollections.observableArrayList(series);
NumberAxis yAxis = new NumberAxis();
yAxis.setAutoRanging(false);
yAxis.setLowerBound(1);
yAxis.setUpperBound(4);
LineChart<Number, Number> root = new LineChart<Number, Number>(new NumberAxis(), yAxis, seriesList);
stage.setScene(new Scene(root));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}