Stackedbar JavaFX未向上显示



请帮帮我我试着在myproject上创建javafx堆叠栏。我很困惑创建这个栏,这对我来说并不常见。我读过任何关于堆叠溢出的问题和答案,但我的程序仍然没有出现。这是我的密码。

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程序就是这样显示的在此处输入图像描述

请帮帮我

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

StackedBarChart chartBar = new StackedBarChart(xaxis,yaxis);

相关内容

  • 没有找到相关文章

最新更新