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

[Charts] Support "missing value": It's not possible to add data points with no value ('null') to a LineChart

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • 7u7
    • javafx
    • Windows7 & 8, eclipse 4.3.1 RCP with SWT, Java JDK 8

    Description

      In statistical data environment where you use line charts to display timeseries it is quite usual that timeseries contain 'empty' values for a specific timestamp.This is called a missing value and may not be changed to the value 0.0, because otherwise one could not distinguish between a real double value 0.0 and a missing value.
      However it is not possible to use a LineChart for that purpose. See following simple code snippet:
        VBox root = new VBox();
        CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("days");
        NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("USD");
        XYChart.Series<String, Double> values = new XYChart.Series<String, Double>();
        values.getData().add(new Data<String, Double>("2000-01-01", 13.2));
        values.getData().add(new Data<String, Double>("2000-01-02", null));
        values.getData().add(new Data<String, Double>("2000-01-03", 14.1));
        values.getData().add(new Data<String, Double>("2000-01-04", 11.6));
        values.getData().add(new Data<String, Double>("2000-01-05", 0.0));
        values.getData().add(new Data<String, Double>("2000-01-06", 9.82));
        XYChart.Series<String, Double> series = values;
        LineChart lineChart = new LineChart(xAxis, yAxis);
        lineChart.getData().add(values);
        root.getChildren().addAll(lineChart);
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();

      At initialization time a NPE is thrown because in the method ValueAxis.invalidateRange() an unchecked attempt is made to access the value:
        ValueAxis class, Line 443: dataValue.doubleValue()
      Unfortunately there seems to be no way to circumvent this issue.

      You might argue that's not a bug, but a feature request. We don't agree. Everybody dealing with real world timeseries data will sooner or later stumble over this issue and get stuck. At least for us who wanted to migrate some of our JFreeChart charts to JavaFX LineChart, it was a show stopper.

      Attachments

        Activity

          People

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Imported: