Search code examples
javachartsjfreechartepoch

JFreeChart xAxis as milliseconds


in JFreeChart my date values are coming into my program in the form of long time in milliseconds. I therefore convert it to RegularTimePeriod class using FixedMillisecond class. Unfortunately, the chart I am displaying is still using the milliseconds as the xAxis values, rather than printing nice dates/days etc. toString method on FixedMillisecond class returns very nice, formatted string denoting day, hour, seconds etc. but it is not the case for the axis rendering. Is there a way to override this behaviour?


Solution

  • Yes - assuming you're using a DateAxis, you can set the DateFormat

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));