Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091757

[ValueAxis] AutoRanging: Ignore NaN and null for internal calculation of dataMaxValue and dataMinValue

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u20
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7 64bit, JDK 8u20 Build b23 64bit

      Description

      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);
      }

      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            aliebelt Andreas Liebelt
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: