bBar с отрицательным значением не отображается на графике. Любое решение?
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ColoredStackBarChart extends Application {
private BarChart<String, Number> chart;
@Override
public void start(Stage primaryStage) throws Exception {
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
this.chart = new BarChart<>(xAxis,yAxis);
this.chart.setAnimated(false);
this.chart.setBarGap(0);
this.chart.setCategoryGap(0);
StackedBarChart<String, Number> chart = new StackedBarChart(xAxis, yAxis);
chart.setLegendVisible(false);
xAxis.getCategories().addAll("A", "B");
XYChart.Series<String, Number> series1 = new XYChart.Series();
XYChart.Data aBar = new XYChart.Data("A", 100);
series1.getData().add(aBar);
XYChart.Series<String, Number> series2 = new XYChart.Series();
XYChart.Data bBar = new XYChart.Data("B", -100);
series2.getData().add(bBar);
chart.getData().addAll(series1, series2);
// NOTE can only set colors after they have been added to the chart.
aBar.getNode().setStyle("-fx-background-color: green");
bBar.getNode().setStyle("-fx-background-color: red");
VBox vbox = new VBox(this.chart);
Scene scene = new Scene(vbox, 400, 200);
primaryStage.setScene(scene);
primaryStage.setHeight(600);
primaryStage.setWidth(400);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}