Search code examples
javaswingjfreechart

Custom X Axis Label on JFreeChart DTSC


I have a JFreeChart to display speed variation. I have used MilliSecondDTSC and MultipleOfMilliSeconds classes to display 10 samples per second (100ms refresh rate). On X-Axis, it shows current time. I want that X-Axis should start with 00:00:00 and increase with time rather than current time, is there any way to achieve this ?

enter image description here


Solution

  • If you use the Java epoch as your baseline:

    Date date = new Date(0L);
    

    Set the format and time zone you want on your domain axis:

    DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    domain.setDateFormatOverride(df);