ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to set up the TimeZone?
Posted by lizhi on Mar-19-2021 22:48
How to set up the chart's TimeZone  to show a time-series data?
I set TimeZone "GMT" but ChartDirector use local-time to display the chart.


   Some demo code as following:

+++++++++++++++++++++++++++++++++++++++++++++++

XYChart c = new XYChart( width, height );

Date nbd = new Date( (long)( ( ed.getTime() - bd.getTime() ) * left ) + bd.getTime() );
Date ned = new Date( (long)( ( ed.getTime() - bd.getTime() ) * right ) + bd.getTime() );

c.yAxis().setDateScale( nbd, ned );
c.addBoxWhiskerLayer( Chart.CTime( bds ), Chart.CTime( eds ), null, null, null, 0x00cc00, Chart.SameAsMainColor, Chart.SameAsMainColor );
+++++++++++++++++++++++++++++++++++++++++++++++

thanks

  Re: How to set up the TimeZone?
Posted by Peter Kwan on Mar-20-2021 15:27
Hi lizhi,

ChartDirector does not need time zone. It just displays the yyyy-mm-dd hh:nn:ss from your input.

For example, if you use Chart.CTime(2021, 3, 20, 17, 45, 10), then it just displays 2021-03-20 17:45:10. It does not need to know what is the time zone.

From your code, it seems it is written in Java. If you use Chart.CTime(d) where d is a java.util.Date, then it obtains the yyyy-mm-dd hh:nn:ss from the Date object using d.getYear(), d.getMonth(), etc.. If you see local time, it is probably because the Date object uses local time zone to determine the yyyy-mm-dd hh:nn:ss.

If you want to control the time zone to use, you may use the GregorianCalendar, which is also support in ChartDirector for Java. The GregorianCalendar has an API to configure the time zone. For example:

GregorianCalendar startGMT = new GregorianCalendar(myTimeZone);
startGMT.setTime(d);

then use Chart.CTime(startGMT).

Another method is use to Chart.CTime(yyyy, mm, dd, hh, nn, ss) to directly specify the date/time you want to see on the chart.

Regards
Peter Kwan