Search code examples
javajfreechart

Disable date-formatting for domain axis in JFreeChart when x-data is Long


I'm using an XYPlot (ChartFactory.createXYStepChart) and the problem is the X-Axis is sample frames whose type is long, so I'm populating my XYSeries by calling xyseries.add(long, double). The result is that JFreeChart automatically interprets the x-values as Date instances, rendering them as something that looks like SMPTE time code:

enter image description here

Instead I want to show the X values as plain (integer number) sample frames. How can I tell the plot or the renderer to revert to default numeric formatting, leaving the longs as longs?


Solution

  • ChartFactory.createXYStepChart() creates a DateAxis for the xAxis, as seen here. DateAxis interprets your long values as milliseconds since the epoch; it displays them as dates. You can either

    • Create a new NumberAxis and use it in a call to the plot's setDomainAxis() method.

    • Create your own factory method that instantiates NumberAxis directly; a related example is shown here.