I have a swing program and i am trying to incorporate a JavaFX bar graph in my program.
How can I put it in a JPanel
?
or
Is there a way to put this code in a ActionListerner
? So I can run it after pressing a button.
public static void start(Stage stage) {
String judge1 = "Judge 1";
String judge2 = "Judge 2";
String judge3 = "Judge 3";
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final BarChart<String,Number> bc =
new BarChart<String,Number>(xAxis,yAxis);
xAxis.setLabel("Judges");
yAxis.setLabel("Run");
XYChart.Series series1 = new XYChart.Series();
series1.setName("Run 1");
series1.getData().add(new XYChart.Data(judge1, 1));
series1.getData().add(new XYChart.Data(judge2, 3));
series1.getData().add(new XYChart.Data(judge3, 2));
XYChart.Series series2 = new XYChart.Series();
series2.setName("Run 2");
series2.getData().add(new XYChart.Data(judge1, 5));
series2.getData().add(new XYChart.Data(judge2, 4);
series2.getData().add(new XYChart.Data(judge3, 4));
Scene scene = new Scene(bc,800,600);
bc.getData().addAll(series1, series2);
stage.setScene(scene);
stage.show();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…