I have a database where I'm extracting data to generate an XYPlot where the x-axis is a TimeSeries. When I read the data into my software into a GregorianCalendar value and display the date/time, I get the correct value (relative to the database values). Then I load that value into a Millisecond object, which is then used in a call to TimeSeries#add(RegularTimePeriod period, double value) to load a dataset, but when the data is displayed on the chart, the date/time has been shifted the distance to my time zone (Mountain). The weird thing is that when I displayed my original database date with a print statement ( GregorianCalendar#getTime().toString() ), it displays the date in my local time zone. But the value displayed on the graph is shift over another time zone. For example, my database date displayed with the code above generates:
Mon Dec 15 15:14:06 MST 2008
but my graphics program displays:
15 Dec 2008 08:14 MST
using a formatter like DateFormat dateFormat = new SimpleDateFormat( "dd-MMM-yyyy HH:mm z" );
I tried using the constructor for Millisecond where I specified the timezone as GMT (as below where timestamp is a GregorianCalendar value) but that didn't work.
Code: Select all
millisecondTime = new Millisecond( timestamp.getTime(), TimeZone.getTimeZone( "GMT" ), new Locale( "eng" ) );
This shift is a little bit of annoyance but the application works even though the times are not correct. But it seems to create a real problem when I want to use the crosshair feature to retrieve specific values on the plot. The following code fails:
Code: Select all
double xx = this.plot.getDomainCrosshairValue();
long millis = (long) this.plot.getDomainCrosshairValue();
if ( millis <= 0 ) return;
String dateText = this.dateFormat.format( new Date( millis ) );
this.crosshairDateValue.setText( dateText );
TimeSeries ts = this.pricesDataSet.getSeries( 0 );
TimeSeriesDataItem dataItem = ts.getDataItem( new Millisecond( new Date( millis ) ) );
int item = ts.getIndex( new Millisecond( new Date( millis ) ) );
Note that I display the date first in a JLabel (this.crosshairDateValue) and it agrees with what is displayed on the graph. But when I retrieve a TimeSeriesDataItem or simply get the index of the TimeSeries for the Millisecond value returned (I did both to see what is happening), it fails (dataItem = null & item < 0). If I go into my debugger and get a millisecond value from the database via GregorianCalendar and use that value to retrieve an TimeSeriesDataItem, it works! So how can it change from the time it is loaded into a TimeSeries/DataSet and when it is retrieved with a crosshair?
Lord I hope one of you wonderful people out there has a handle on this problem. I've tried everything I can, even changing the timezone in the Millisecond constructor to "MST" or using the fullname option "America/Denver" and nothing works.