javajavafxstackedbarseries

Stackedbar JavaFX Not Showing UP


help me please i was try to create javafx stacked bar on myproject. i'm so confused to create that bar, it's not common for me. i have read any ask question and any answer on stacked over flow but, my program still not showing up. this is my code.

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);  

    }      
}

create FXML with scene builder, code editor on netbeans Program just show like this enter image description here

Help me please


Solution

  • You're creating a new StackedBarChart inside your start method. You then configure that chart and never add it to the scene. However, you are already injecting a StackedBarChart via FXML—you should be configuring that one. Remove the following line from start:

    StackedBarChart chartBar = new StackedBarChart(xaxis,yaxis);