Stackedbar JavaFX 未显示

Stackedbar JavaFX Not Showing UP

请帮帮我 我试图在 myproject 上创建 javafx 堆积条。我很困惑创建那个酒吧,这对我来说并不常见。我已经阅读了关于 stacked over flow 的任何提问和任何答案,但是我的程序仍然没有出现。 这是我的代码。

package stackedbar;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Label;

/**
 *
 * @author kuupie
 */
public class FXMLDocumentController implements Initializable {

    private Label label;
    @FXML
    private StackedBarChart<String, Number> chartBar;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        start();
    } 

public void start() {  
    // TODO Auto-generated method stub  
    //Configuring xaxis and yaxis   
    CategoryAxis xaxis = new CategoryAxis();  
    NumberAxis yaxis = new NumberAxis(1000,300000,1000);  
    xaxis.setLabel("Months");  
    yaxis.setLabel("Number of users");  

    //Configuring StackedBarChart   
    StackedBarChart chartBar = new StackedBarChart(xaxis,yaxis);  
    chartBar.setTitle("Popularity of Programming languages");  

    //Configuring series for java  
    XYChart.Series java = new XYChart.Series<>();  
    java.setName("java");  
    java.getData().add(new XYChart.Data<>("Jan",10000));  
    java.getData().add(new XYChart.Data<>("Jan",130000));  
    java.getData().add(new XYChart.Data<>("Feb",50000));  
    java.getData().add(new XYChart.Data<>("Mar",60300));  
    java.getData().add(new XYChart.Data<>("Apr",105600));  
    java.getData().add(new XYChart.Data<>("May",50600));  
    java.getData().add(new XYChart.Data<>("Jun",103000));  
    java.getData().add(new XYChart.Data<>("Jul",104500));  
    java.getData().add(new XYChart.Data<>("Aug",203000));  
    java.getData().add(new XYChart.Data<>("Sep",103400));  
    java.getData().add(new XYChart.Data<>("Oct",105600));  
    java.getData().add(new XYChart.Data<>("Nov",102400));  
    java.getData().add(new XYChart.Data<>("Dec",200000));  

    //Adding series java to the stackedbarchart  
    chartBar.getData().add(java);  

    //Configuring series python   
    XYChart.Series python = new XYChart.Series<>();  
    python.setName("python");  
    python.getData().add(new XYChart.Data<>("Jan",50000));  
    python.getData().add(new XYChart.Data<>("Jan",14300));  
    python.getData().add(new XYChart.Data<>("Feb",50400));  
    python.getData().add(new XYChart.Data<>("Mar",100500));  
    python.getData().add(new XYChart.Data<>("Apr",104000));  
    python.getData().add(new XYChart.Data<>("May",134000));  
    python.getData().add(new XYChart.Data<>("Jun",60000));  
    python.getData().add(new XYChart.Data<>("Jul",78000));  
    python.getData().add(new XYChart.Data<>("Aug",89000));  
    python.getData().add(new XYChart.Data<>("Sep",150000));  
    python.getData().add(new XYChart.Data<>("Oct",120000));  
    python.getData().add(new XYChart.Data<>("Nov",109450));  
    python.getData().add(new XYChart.Data<>("Dec",50450));  

    //adding python series to the stackedbarchart   
    chartBar.getData().add(python);  

    }      
}

在 netbeans 上使用场景生成器、代码编辑器创建 FXML 程序就这样显示 enter image description here

请帮帮我

您正在 start 方法中创建一个新的 StackedBarChart。然后您配置 that 图表并且从不将其添加到场景中。但是,您已经通过 FXML 注入了 StackedBarChart——您应该配置那个。从 start 中删除以下行:

StackedBarChart chartBar = new StackedBarChart(xaxis,yaxis);