Reputation: 69
I am trying to import javafx.scene.chart.LineChart; into my code, but for whatever reason it just keeps coming up as an error. I am currently using Eclipse, but I have also tried the same exact file on NetBeans and neither seems to work. I can use the constructor LineChart lineChart = new LineChart();
but I am trying to use the LineChart<X,Y>
class. If someone could point me in the right direction I would appreciate it. Here is the full code.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart; // <---- Problem Line
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class LineChart extends Application{
@Override
public void start(Stage stage){
stage.setTitle("Test");
//Axis
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Test Axis");
//Create chart
final LineChart<Number, Number> lineChart = new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle("Test");
//Series
XYChart.Series series = new XYChart.Series();
series.setName("Test Series");
//Adding the Data
series.getData().add(new XYChart.Data(1,50));
series.getData().add(new XYChart.Data(2,60));
series.getData().add(new XYChart.Data(3,70));
series.getData().add(new XYChart.Data(4,80));
series.getData().add(new XYChart.Data(5,90));
Scene scene = new Scene(lineChart, 400, 300);
lineChart.getData().add(series);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args){
launch(args);
}
}
Upvotes: 0
Views: 160
Reputation: 12480
You need to change the name of your class to something other than LineChart
:
public class MyOwnLineChart_2 /* or similar */
Upvotes: 1