I want to add a Pie chart inside a JPanel. I have gone through this and this. But it didnt helped me.
I tried this code in the debugger but it is not getting pass line X. Somehow setScene
function is not working and pie chart is not visible in the panel.
Here's my code:
private void add_pie_chart(JPanel panel)
{
JFXPanel dataPanel = new JFXPanel();
PieChart pieChart = new PieChart();
ObservableList<PieChart.Data> data= FXCollections.observableArrayList(
new PieChart.Data("test1", 25),
new PieChart.Data("test 2", 25),
new PieChart.Data("test 3", 25),
new PieChart.Data("test 4", 25)
);
pieChart.setData(data);
pieChart.setTitle("test");
pieChart.setLabelsVisible(true);
Group root = new Group();
root.getChildren().add(pieChart);
Scene scene = new Scene(root);
dataPanel.setScene(scene); //line X
//not getting executing
panel.add(dataPanel, BorderLayout.CENTER);
panel.setVisible(true);
}
I am not sure why this is happening. Plz help..
Any help is appreciated. Thanks in advance...