I need some basic help formatting date/time so that I can add it to my JFreeChart TimeSeries. Because my code is adding duplicates I get the error below the second time through the loop.
I have a temperature sensor we use in healthcare and I need to plot the temp that is read every 30 minutes. So I need my x-axis to be Month-Day-Hour-Minute but I just dont know how to get my time formatted correctly. The line below were I am having issue specifically is " timeSeries.add(new Day(gc.getTime()), temp );"
It's been a really long time since college so I apologize, I think I am close but just can't close the gap. Any help would be appreciated.
thx! L
Output
Sat Nov 20 12:41:00 PST 2021: 72.5 F
TimeSeries.add 20-November-2021
Sat Nov 20 13:11:00 PST 2021: 70.7 F
TimeSeries.add 20-November-2021
Run-time Error when adding duplicates
Exception in thread "main" org.jfree.data.general.SeriesException: You are attempting to add an observation for the time period 20-November-2021 but the series already contains an observation for that time period. Duplicates are not permitted. Try using the addOrUpdate() method.
at org.jfree.data.time.TimeSeries.add(TimeSeries.java:701)
at org.jfree.data.time.TimeSeries.add(TimeSeries.java:746)
at org.jfree.data.time.TimeSeries.add(TimeSeries.java:732)
at dumpMission.main(dumpMission.java:212)
TimeSeries timeSeries = new TimeSeries("Date");
TimeSeriesCollection timeSeriesCollectionTemps = new TimeSeriesCollection();
long time = time_stamp.getTime().getTime() + owc.getFirstLogOffset(state);
GregorianCalendar gc = new GregorianCalendar();
for (int i = 0; i < log.length; i++){
gc.setTime(new Date(time));
System.out.println(gc.getTime() + ": " + Convert.toFahrenheit(owc.decodeTemperature(log [i])) + " F");
time += sample_rate * 60 * 1000;
double temp = Convert.toFahrenheit(owc.decodeTemperature(log [i]));
System.out.println("TimeSeries.add " + new Day(gc.getTime()));
//add needs org.jfree.data.time.RegularTimePeriod
//need to plot month-day-hour-minute
timeSeries.add(new Day(gc.getTime()), temp ); // NEED HELP to get into unique month/day/hour/minute
timeSeriesCollectionTemps.addSeries(timeSeries);
}