2

I am using JFreechart to create a Gantt chart, however the Date (X-axis) is being displayed in the Date format HH:MM:SS.

Is there any way to get this x-axis to only display milliseconds? Since this is a Gantt chart my x-axis values are of type SimpleTimePeriod which I constructed with milliseconds.

Thank you very much for any help.

user_48349383
  • 517
  • 6
  • 13

2 Answers2

3

Assuming ChartFactory.createGanttChart(), you can specify any desired format when calling setNumberFormatOverride() on the plot's DateAxis. There's a related example here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I believe it is a CategoryAxis and not a DateAxis. – user_48349383 Sep 21 '12 at 16:33
  • One of each: [`createGanttChart()`](http://www.jfree.org/jfreechart/api/javadoc/src-html/org/jfree/chart/ChartFactory.html#line.1303). – trashgod Sep 21 '12 at 16:41
  • Oh yes of course you are right! I will look into this further, but it seems that there aren't any built-in formats for displaying the time in milliseconds. So I guess I should extend NumberFormat with a custom class? – user_48349383 Sep 21 '12 at 16:54
  • You're welcome; you may have already found `SimpleDateFormat` and `SSS`. – trashgod Sep 21 '12 at 16:59
0

This also works:

CategoryPlot plot = (CategoryPlot) chart.getPlot(); 
DateAxis range = new DateAxis("Date");
range.setDateFormatOverride(new SimpleDateFormat("ss.SSS"));
plot.setRangeAxis(range);
2c00L
  • 495
  • 12
  • 29