Vertical date axis on TimeSeriesChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
IanMayo
Posts: 9
Joined: Mon Oct 31, 2005 10:15 am
Location: UK

Vertical date axis on TimeSeriesChart

Post by IanMayo » Fri Jan 23, 2009 1:00 pm

Hi all,
I'd like to produce a scatter plot with date data on the vertical axis. TimeSeriesChart appears to only support date on the horizontal axis. Can this be overridden? Or should I just work from an XYChart?

thanks in advance,
Ian

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Jan 23, 2009 1:44 pm

You can just replace the range axis (which is, by default, a NumberAxis) with a new DateAxis:

Code: Select all

XYPlot plot = (XYPlot) chart.getPlot();
plot.setRangeAxis(new DateAxis("Date"));
Note that the y-values from your dataset will now be interpreted as "milliseconds since 1-Jan-1970" as in java.util.Date.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

IanMayo
Posts: 9
Joined: Mon Oct 31, 2005 10:15 am
Location: UK

Post by IanMayo » Fri Jan 23, 2009 2:46 pm

thanks for coming back to me David,

Unfortunately I omitted to indicate that I wish to show my 'range' data (distance in this instance) along the horizontal axis. Extending from your example, I would replace the domain axis with a NumberAxis. At this point, would it have just been better to start with an XYPlot?
cheers,
Ian

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Jan 23, 2009 3:32 pm

OK, is the date axis for your y-values? If yes, and you want the y-values along the horizontal axis, then you can call plot.setOrientation(PlotOrientation.HORIZONTAL). This switches the orientation of the plot, so that the x-axis is the vertical axis and the y-axis is the horizontal axis.

Note that in JFreeChart domainAxis == xAxis and rangeAxis == yAxis. And also, a time series chart *is* an XYPlot, but one that has had its xAxis changed from a NumberAxis to a DateAxis (there's nothing to stop you from changing it back to a NumberAxis again).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

IanMayo
Posts: 9
Joined: Mon Oct 31, 2005 10:15 am
Location: UK

Post by IanMayo » Fri Jan 23, 2009 3:40 pm

David,
spot-on, thanks. I'll do that.

Cheers,
Ian

Locked