Chart crashes if I setLabelsVisible(false):
Caused by: java.lang.NullPointerException
at javafx.scene.chart.PieChart.layoutChartChildren(PieChart.java:548)
at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:84)
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.chart.PieChart;
import javafx.util.Duration;
/**
* An advanced pie chart with a variety of actions and settable properties.
*
* @see javafx.scene.chart.PieChart
* @see javafx.scene.chart.Chart
*/
public class TestApp3 extends Application {
private int itemNameIndex = 1;
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setScene(new Scene(root));
root.getChildren().add(createChart());
}
protected PieChart createChart() {
final PieChart pc = new PieChart(FXCollections.observableArrayList(
new PieChart.Data("Sun", 20),
new PieChart.Data("IBM", 12),
new PieChart.Data("HP", 25),
new PieChart.Data("Dell", 22),
new PieChart.Data("Apple", 30)
));
pc.setLabelsVisible(false);
// setup chart
pc.setId("BasicPie");
pc.setTitle("Pie Chart Example");
return pc;
}
@Override public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}
Caused by: java.lang.NullPointerException
at javafx.scene.chart.PieChart.layoutChartChildren(PieChart.java:548)
at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:84)
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.chart.PieChart;
import javafx.util.Duration;
/**
* An advanced pie chart with a variety of actions and settable properties.
*
* @see javafx.scene.chart.PieChart
* @see javafx.scene.chart.Chart
*/
public class TestApp3 extends Application {
private int itemNameIndex = 1;
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setScene(new Scene(root));
root.getChildren().add(createChart());
}
protected PieChart createChart() {
final PieChart pc = new PieChart(FXCollections.observableArrayList(
new PieChart.Data("Sun", 20),
new PieChart.Data("IBM", 12),
new PieChart.Data("HP", 25),
new PieChart.Data("Dell", 22),
new PieChart.Data("Apple", 30)
));
pc.setLabelsVisible(false);
// setup chart
pc.setId("BasicPie");
pc.setTitle("Pie Chart Example");
return pc;
}
@Override public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}