TableCell: how to use a StackedBarChart (or is it impossible)?

喜你入骨 提交于 2019-11-29 16:56:31

Here's just where I copied stuff into my CellFactory

    col3.setCellFactory((TableColumn<Data, Data> param) -> {
        return new TableCell<Data, Data>() {

            @Override
            protected void updateItem(Data item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) setGraphic(null);
                else {
                    super.updateItem(item, empty);
                    if (item == null || empty) {
                        setGraphic(null);
                    } else {
                        NumberAxis xAxisHoriz = new NumberAxis(0, 2000, 1000);
                        CategoryAxis yAxisHoriz = new CategoryAxis(FXCollections.observableArrayList(""));
                        XYChart.Series<Number, String> series1Horiz = new XYChart.Series<>();
                        XYChart.Series<Number, String> series2Horiz = new XYChart.Series<>();
                        StackedBarChart<Number, String> sbcHoriz = new StackedBarChart<>(xAxisHoriz, yAxisHoriz);
                        sbcHoriz.getData().setAll(series1Horiz, series2Horiz);

                        yAxisHoriz.setStyle("-fx-border-color: transparent transparent transparent transparent;"
                                + "-fx-tick-labels-visible: false;"
                                + "-fx-tick-mark-visible: false;"
                                + "-fx-minor-tick-visible: false;"
                                + "-fx-padding: 0 0 0 0;");

                        xAxisHoriz.setStyle("-fx-border-color: transparent transparent transparent transparent;"
                                + "-fx-tick-labels-visible: false;"
                                + "-fx-tick-mark-visible: false;"
                                + "-fx-minor-tick-visible: false;"
                                + "-fx-padding: 0 0 0 0;");

                        sbcHoriz.setHorizontalGridLinesVisible(false);
                        sbcHoriz.setVerticalGridLinesVisible(false);
                        sbcHoriz.setLegendVisible(false);
                        sbcHoriz.setAnimated(false);

                        xAxisHoriz.setMaxWidth(100);
                        sbcHoriz.setMaxWidth(100);
                        sbcHoriz.setPadding(Insets.EMPTY);

                        sbcHoriz.setCategoryGap(0);
                        setGraphic(sbcHoriz);
                        series1Horiz.getData().setAll(new XYChart.Data(item.num1.get(), ""));
                        series2Horiz.getData().setAll(new XYChart.Data(item.num2.get(), ""));
                    }
                }
            }
        };
    });

and also after I set this tv.setFixedCellSize(30);

I also had to change the column width to 200, I can't make the chart smaller.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!