-1

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);
    }
}
trashgod
  • 200,320
  • 28
  • 229
  • 974
  • 1
    Instead of `System.out.println` , store `data` into a `List` or `StringBuilder`. Or actually parse each line into something you can plot – OneCricketeer May 17 '22 at 21:09
  • You are already creating an instance of `JFreeChart`. You picked that deliberately, so why don't you read its documentation? You also need to add it to the visible Frame. – f1sh May 17 '22 at 21:16
  • If this is not a duplicate, please [edit] your question to include a [mre] and sample text file that shows your revised approach. – trashgod May 17 '22 at 21:41

0 Answers0