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

后端 未结 1 656
生来不讨喜
生来不讨喜 2020-12-22 01:47

The trigger for my experiment was a recent question - one cell in a row should visualize the relative proportion of values in several cell values in the same row. In fx, suc

相关标签:
1条回答
  • 2020-12-22 02:49

    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.

    sample pic

    0 讨论(0)
提交回复
热议问题