FULL PRODUCT VERSION :
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.10166]
A DESCRIPTION OF THE PROBLEM :
In StackedBarChart there is an implementation that after category removal, Data items are also removed from display. But if you want to add again the same category (String) is a problem with display bar plot for this category. It still remembers in categoryMap old values and any new Data item are plotted above old notvisualed bars.
Problem is also in case of removing Data items from series instead of case by removing category.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Define CategoryAxis with custom specified category collection (autoRanging == false).
2. Add StackedBarChart with CategoryAxis and NumberAxis.
3. Add series to StackedBarChart with Data items for each category.
4. Remove one of category by CategoryAxis.getCategories().remove("CATEGORY").
5. Add category with the same name as previously removed.
6. Add new Data item with xValue set to the name of added category and any yValue.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After step 4: entire bar with date from removed categories should me removed from display. All Data item references should be removed from StackedBarChart object and its private collections.
After step 5 and 6: in place of new added category there should be new bar displayed from level zero.
ACTUAL -
After step 4: bar plot is removed from display but you can check that there are still hard references to data items in StackedBarChart private collections (eg. categoryMap).
After step 5 and 6: new bar plot is displayed incorrectly - not from level 0 on the axis but from the level of previosuly removed data item.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class AppCharts extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
StackPane stackPane = new StackPane();
Button button = new Button("add");
Button buttonRemove = new Button("remove");
HBox dock = new HBox();
Scene scene = new Scene(stackPane);
CategoryAxis categoryAxis = new CategoryAxis(FXCollections.observableArrayList("MAIN", "LOW", "HIGH", "OTHER"));
NumberAxis numberAxis = new NumberAxis(0.0, 200.0, 10.0);
StackedBarChart<String, Number> chart = new StackedBarChart<>(categoryAxis, numberAxis);
XYChart.Series<String, Number> series1 = new XYChart.Series<>();
series1.getData().add(new XYChart.Data<>("MAIN", 30));
series1.getData().add(new XYChart.Data<>("LOW", 20));
series1.getData().add(new XYChart.Data<>("HIGH", 50));
series1.getData().add(new XYChart.Data<>("OTHER", 30));
chart.getData().add(series1);
chart.setMinWidth(200);
chart.setMinHeight(400);
button.setAlignment(Pos.TOP_LEFT);
dock.getChildren().addAll(button, buttonRemove);
stackPane.getChildren().addAll(chart, dock);
primaryStage.setScene(scene);
primaryStage.show();
button.setOnAction(event -> {
XYChart.Data<String, Number> newData = new XYChart.Data<>("LOW",70);
categoryAxis.getCategories().add(1, "LOW");
series1.getData().add(newData);
});
buttonRemove.setOnAction(event -> {
//ugly workaround correcting bug only from visual perspective
//series1.getData().get(1).setYValue(0);
categoryAxis.getCategories().remove("LOW");
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Only ugly workaround by setting yValue = 0 for all Data items (in each series) from removed category before actual category remove.
This is ony visual workaround but there ar still problems with internal chart consistency and memory leaks from unbounded Data items.
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.10166]
A DESCRIPTION OF THE PROBLEM :
In StackedBarChart there is an implementation that after category removal, Data items are also removed from display. But if you want to add again the same category (String) is a problem with display bar plot for this category. It still remembers in categoryMap old values and any new Data item are plotted above old notvisualed bars.
Problem is also in case of removing Data items from series instead of case by removing category.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Define CategoryAxis with custom specified category collection (autoRanging == false).
2. Add StackedBarChart with CategoryAxis and NumberAxis.
3. Add series to StackedBarChart with Data items for each category.
4. Remove one of category by CategoryAxis.getCategories().remove("CATEGORY").
5. Add category with the same name as previously removed.
6. Add new Data item with xValue set to the name of added category and any yValue.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After step 4: entire bar with date from removed categories should me removed from display. All Data item references should be removed from StackedBarChart object and its private collections.
After step 5 and 6: in place of new added category there should be new bar displayed from level zero.
ACTUAL -
After step 4: bar plot is removed from display but you can check that there are still hard references to data items in StackedBarChart private collections (eg. categoryMap).
After step 5 and 6: new bar plot is displayed incorrectly - not from level 0 on the axis but from the level of previosuly removed data item.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class AppCharts extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
StackPane stackPane = new StackPane();
Button button = new Button("add");
Button buttonRemove = new Button("remove");
HBox dock = new HBox();
Scene scene = new Scene(stackPane);
CategoryAxis categoryAxis = new CategoryAxis(FXCollections.observableArrayList("MAIN", "LOW", "HIGH", "OTHER"));
NumberAxis numberAxis = new NumberAxis(0.0, 200.0, 10.0);
StackedBarChart<String, Number> chart = new StackedBarChart<>(categoryAxis, numberAxis);
XYChart.Series<String, Number> series1 = new XYChart.Series<>();
series1.getData().add(new XYChart.Data<>("MAIN", 30));
series1.getData().add(new XYChart.Data<>("LOW", 20));
series1.getData().add(new XYChart.Data<>("HIGH", 50));
series1.getData().add(new XYChart.Data<>("OTHER", 30));
chart.getData().add(series1);
chart.setMinWidth(200);
chart.setMinHeight(400);
button.setAlignment(Pos.TOP_LEFT);
dock.getChildren().addAll(button, buttonRemove);
stackPane.getChildren().addAll(chart, dock);
primaryStage.setScene(scene);
primaryStage.show();
button.setOnAction(event -> {
XYChart.Data<String, Number> newData = new XYChart.Data<>("LOW",70);
categoryAxis.getCategories().add(1, "LOW");
series1.getData().add(newData);
});
buttonRemove.setOnAction(event -> {
//ugly workaround correcting bug only from visual perspective
//series1.getData().get(1).setYValue(0);
categoryAxis.getCategories().remove("LOW");
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Only ugly workaround by setting yValue = 0 for all Data items (in each series) from removed category before actual category remove.
This is ony visual workaround but there ar still problems with internal chart consistency and memory leaks from unbounded Data items.
- relates to
-
JDK-8115252 [StackedBarChart] is wrongly animated
-
- Closed
-