Menu

Time is off for date/time X axis

Xandrios
2013-05-10
2013-05-10
  • Xandrios

    Xandrios - 2013-05-10

    Hi,

    I am using a Spline graph with a date+time X axis. The points (with their dates) are fed from a server. The issue that I am experiencing is that times are shown incorrectly.

    The server sends the timestamps for the X axis as a String, which is then parsed.

    String dateString = "2013-05-10 20:15:16 +200"; //from server
    long date = dateTimeFormatter.parse(dateString).getTime(); 
    Date dateObj = new Date(date);
    String dateStr = dateTimeFormatter.format(dateObj); //"2013-05-10 20:15:16 +200";
    

    The date variable is then passed to the gwt-highcharts Point object. However in the chart it shows up as either:

    18:15:16 (When the client is GMT+2)
    17:15:16 (When the client is GMT+3)

    So there clearly is a correlation. However I fail to see why the dateTimeFormatter is able to recognize the right date/timezone, but the highcharts graph does not.

    I realize the the best way would be to use Date objects from the server, so that the time can be corrected during (de)serialization of GWT rpc. However I am not sure if that would solve the issue in this case, as the dateObj seems to contain the right value. The issue seems to be with displaying that in the timezone of the visitor. Any opinions?

    Thanks!

     
  • Shawn Quinn

    Shawn Quinn - 2013-05-10

    Not sure if this is the issue you're seeing, but have you tried disabling the UTC logic in Highcharts? E.g.

    Highcharts.setOptions(new Highcharts.Options()
        .setGlobal(new Global()
            .setUseUTC(false)
        )
    );
    

    Make sure you make that call before you render the chart. Let us know if that affects the behavior you're seeing or not...

     
  • Xandrios

    Xandrios - 2013-05-10

    Hi Shawn, thank you so much.

    This did the trick indeed! Reading up on the highcharts global options it even sounds somewhat logical that this would be turned on by default - although I cannot explain why people in different timezones did see different results. When turning it off the times are nicely displayed in the correct local timezone.

    I also realize that this actually has nothing to do with the GWT wrapper implementation, so I appreciate your help in this matter. Thanks!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.