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

StackedAreaChart ClassCastException on CategoryAxis

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 7u6
    • javafx
    • java version "1.7.0_06-ea"
      Java(TM) SE Runtime Environment (build 1.7.0_06-ea-b19)
      Java HotSpot(TM) 64-Bit Server VM (build 23.2-b08, mixed mode)

      javafx.runtime.version: 2.2.0-beta-b17

    Backports

      Description

        StackedAreaChart appears to be broken when using a CategoryAxis (works fine with Number/Number).

        The following code should reproduce - works correctly with a StackedBarChart - however gets a ClassCastException on the StackedAreaChart.

        Exception:
        Caused by: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
        at javafx.scene.chart.CategoryAxis.getDisplayPosition(CategoryAxis.java:60)
        at javafx.scene.chart.StackedAreaChart.layoutPlotChildren(StackedAreaChart.java:431)
        at javafx.scene.chart.XYChart.layoutChartChildren(XYChart.java:687)
        at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:81)
        at javafx.scene.Parent.layout(Parent.java:1018)

        Example:


        import java.util.Arrays;

        import javafx.application.Application;
        import javafx.collections.FXCollections;
        import javafx.scene.Group;
        import javafx.scene.Scene;
        import javafx.scene.chart.CategoryAxis;
        import javafx.scene.chart.NumberAxis;
        import javafx.scene.chart.StackedAreaChart;
        import javafx.scene.chart.StackedBarChart;
        import javafx.scene.chart.XYChart;
        import javafx.stage.Stage;

        public class TestChart extends Application {
        public static void main(String[] args) {
                launch(args);
            }
             
            @Override
            public void start(Stage primaryStage) {
                CategoryAxis xAxis = new CategoryAxis(FXCollections.observableArrayList(Arrays.asList("Jan", "Feb", "Mar", "Apr")));
                xAxis.setLabel("Month");

                NumberAxis yAxis = new NumberAxis();
                yAxis.setLabel("Value");
                
                XYChart<String,Number> stackedChart = new StackedAreaChart<>(xAxis,yAxis);
        // XYChart<String,Number> stackedChart = new StackedBarChart<>(xAxis,yAxis);

                XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
                series1.setName("Series 1");
                series1.getData().add(new XYChart.Data<String,Number>("Jan", 100));
                series1.getData().add(new XYChart.Data<String,Number>("Feb", 200));
                series1.getData().add(new XYChart.Data<String,Number>("Mar", 50));
                series1.getData().add(new XYChart.Data<String,Number>("Apr", 75));
         
                XYChart.Series<String,Number> series2 = new XYChart.Series<String,Number>();
                series2.setName("Series 2");
                series2.getData().add(new XYChart.Data<String,Number>("Jan", 50));
                series2.getData().add(new XYChart.Data<String,Number>("Feb", 200));
                series2.getData().add(new XYChart.Data<String,Number>("Mar", 260));
                series2.getData().add(new XYChart.Data<String,Number>("Apr", 100));

                stackedChart.getData().add(series1);
                stackedChart.getData().add(series2);
                      
                Group root = new Group();
                root.getChildren().addAll(stackedChart);
                primaryStage.setScene(new Scene(root, 500, 400));
                primaryStage.show();
            }
        }

        Attachments

          Issue Links

            Activity

              People

                psomashe Parvathi Somashekar (Inactive)
                duke J. Duke
                Votes:
                2 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported: