Basically I have a text file with days, minimum and maximum temperatures, and average wind speed. I need to load it into Java and make a chart out of it. This just lets me choose a file, but doesn't put it on the chart which is just blank.
public class MyChart {
static TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries seria1 = new TimeSeries("Nazwa serii");
static JFreeChart chart = ChartFactory.createTimeSeriesChart
("Wykres","Data","Temperatura",dataset,true,true,false);
public MyChart() throws HeadlessException{
try {
File dirPath = new File(System.getProperty("user.dir"));
JFileChooser jchooser = new JFileChooser(dirPath);
int returnVal = jchooser.showSaveDialog(null);
Scanner myReader = new Scanner(dirPath);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
System.out.println(data);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public static void main(String arg[]){
MyChart frame = new MyChart();
ChartFrame frame1=new ChartFrame("TimeSeries Chart",chart);
frame1.setVisible(true);
frame1.setSize(400,300);
}
}