Creating lineChart using JavaFx scene builder


Ive been trying to look on the oracle tutorials on the chart section but so far i have not been able to succeed.

what i want to do is basicly test a lineChart that i have added in my JavaFx scene builder.

so far my code is the following:

    public class SimpleController implements Initializable{

    public Button btn_getData;
    public ProgressBar progressBar;
    public LineChart<String, Integer> lineChart;

    public void initialize(URL arg0, ResourceBundle arg1) {
        // TODO Auto-generated method stu

        XYChart.Series series = new XYChart.Series<>();
        series.getData().add(new XYChart.Data<>("Jan", 23));
        series.getData().add(new XYChart.Data("lol", 2));

As you can see all i want to do is for my program to display a sortof test.

Hope someone is able to help.

Also if you have time to explain what the problem is aswell that would be awesome since im trying to get better at JavaFx :)

11/5/2012 12:57:09 PM

Accepted Answer

Assuming that in your fxml you would have something like fx:id="lineChart" assigned to your LineChart node and a controller assigned to your Parent Node this would probably work.

Also try: series.getData().add(new XYChart.Data<String,Integer>(String,integer)); instead.

12/11/2012 8:36:58 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow