-
Bug
-
Resolution: Fixed
-
P4
-
7u6
-
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
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8129995 | 7u40 | Parvathi Somashekar | P4 | Closed | Fixed |
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();
}
}
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();
}
}
- backported by
-
JDK-8129995 StackedAreaChart ClassCastException on CategoryAxis
-
- Closed
-
- duplicates
-
JDK-8125109 StackedAreaChart throws ClassCastException if x-axis uses string categories
-
- Closed
-