I am encountering some issues with the Class StackedAreaChart and setLowerBound function. When I enable the autoRangingProperty to true, everything works fine.
However, when I disable autoRanging and apply certain parameters, I encounter some bugs.
import java.util.Random;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedAreaChart;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class TestStackedAreaChart extends Application {
StackPane mainGraphStackPane = null;
BorderPane pane;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// /
Random generator = new Random();
XYChart.Series<Number, Number> series1 = new XYChart.Series<>(); // line
XYChart.Series<Number, Number> series2 = new XYChart.Series<>(); // down
XYChart.Series<Number, Number> series3 = new XYChart.Series<>(); // up
for (int i = 1; i < 50; i++) {
Double value = generator.nextDouble() + 1;
series1.getData().add(new XYChart.Data<Number, Number>(i, value));
Double Ymin = value - generator.nextDouble() * 0.2;
series2.getData().add(new XYChart.Data<Number, Number>(i, Ymin));
Double Ymax = (value - Ymin) + generator.nextDouble() * 0.2;
series3.getData().add(new XYChart.Data<Number, Number>(i, Ymax));
}
// /
final NumberAxis xAxisLC = new NumberAxis();
final NumberAxis yAxisLC = new NumberAxis();
/////////what's wrong
yAxisLC.autoRangingProperty().set(false);
yAxisLC.setMinorTickLength(yAxisLC.getTickLength());
yAxisLC.setMinorTickCount(0);
yAxisLC.setUpperBound(2.5);
yAxisLC.setLowerBound(1.0); //when I set 0.0 is OK
yAxisLC.setTickUnit(0.2);
///////
pane = new BorderPane();
mainGraphStackPane = new StackPane();
mainGraphStackPane.getChildren().add(pane);
StackedAreaChart<Number, Number> areaChart = new StackedAreaChart<Number, Number>(
xAxisLC, yAxisLC);
areaChart.setCreateSymbols(false);
areaChart.setAlternativeRowFillVisible(false);
areaChart.setAnimated(false);
areaChart.setLegendVisible(false);
areaChart.getData().add(series2);
areaChart.getData().add(series3);
Scene scene = new Scene(mainGraphStackPane);
mainGraphStackPane.getChildren().add(areaChart);
mainGraphStackPane.getStylesheets().add("chart.css");
stage.setScene(scene);
Group root = new Group();
pane.getChildren().add(root);
stage.show();
stage.setWidth(stage.getWidth() + 1);
stage.setHeight(stage.getHeight() + 1);
}
}
and CSS file
@CHARSET "UTF-8";
.default-color0.chart-area-symbol { -fx-background-color: #e9967a, #ffa07a; }
.default-color1.chart-area-symbol { -fx-background-color: #e9967a, #ffa07a; }
.default-color0.chart-series-area-line { -fx-stroke: #ffaa00; }
.default-color1.chart-series-area-line { -fx-stroke: #ffaa00; }
.default-color0.chart-series-area-fill { -fx-fill: #ffff0055; }
.default-color1.chart-series-area-fill { -fx-fill: #ffaa005
Looking for suggestions or solutions to resolve this issue.