I haven’t used java since version 4 and casting seams to have changed to the point where it’s almost annoying. I don’t understand how to approach the following compile error.
HelloWorld.java:70: error: no suitable method found for
add(Series)
lineChart.getData().add(series);
^
method List.add(int,Series) is not applicable
(actual and formal argument lists differ in length)
method List.add(Series) is not applicable
(actual argument Series cannot be converted to Series by method invocation conversion)
Here is my code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.*;
import javafx.stage.Stage;
import javafx.geometry.Side;
import java.lang.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class HelloWorld extends Application {
@Override public void start(Stage stage) {
Vector <String[]> v = new Vector<String[]>();
try{
File f = new File("audjpy.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
String[] data;
int count = 0;
while ((line = br.readLine()) != null) {
data = line.split(",");
if(count>0)v.add(data);
if(count == 400)break;
count++;
}
br.close();
}catch(IOException e){System.out.println(e);}
stage.setTitle("Line Chart Sample");
//defining the axes
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
yAxis.setSide(Side.RIGHT);
xAxis.setLabel("Number of Month");
//creating the chart
final LineChart<Number,Number> lineChart =
new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
//defining a series
XYChart.Series<Double, Double> series = new XYChart.Series<Double, Double>();
series.setName("My portfolio");
//populating the series with data
//<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
Enumeration<String[]> e = v.elements();
while(e.hasMoreElements()){
String[] data = e.nextElement();
double x = Double.parseDouble(data[4]);
double y = Double.parseDouble(data[5]);
series.getData().add(new XYChart.Data<Double, Double>(x,y));
}
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(1, series);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The reasons seems like it is because you are using
DoubleandNumberinterchangeable, change every generic toNumberand your problem should be solved.