Can JFreeChart do multiple plots between ticks

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Kenny Dubuisson

Can JFreeChart do multiple plots between ticks

Post by Kenny Dubuisson » Thu Oct 03, 2002 7:21 pm

I want to create a chart that shows stock prices. The ticks on the x axis should represent month's. Instead of having one plot point per month, I want to plot every day's price. This effectively give 30 or so plots between x axis ticks. What I'd like to know is if this is possible. If so, could someone point me in the right direction on how to handle this (read JFreeChart newbie into that).

Thanks,
Kenny

David Gilbert

Re: Can JFreeChart do multiple plots between ticks

Post by David Gilbert » Fri Oct 04, 2002 5:16 pm

Hi Kenny,

You can use one (or several) BasicTimeSeries to record daily stock prices (skipping some days if you want to). Add the series to a TimeSeriesCollection and you have a dataset that JFreeChart can work with.

Now, if you create a time series chart with this data, the horizontal axis will be a date axis. But the date axis doesn't know (or care) that your data is DAILY. All it sees is a bunch of x-values that are actually milliseconds since 1 Jan 1970 (the encoding used by java.util.Date). The tick labels on the date axis are independent of the data you are displaying...by default, JFreeChart will try to display as many tick labels as it can without them overlapping. This might be one tick per day, or one tick per week, it all depends on how much room there is to display your chart.

You can set a fixed tick unit size if you want to. Create a new DateUnit and try the setTickUnit method in the DateAxis class (note that this is changing slightly for the next release).

Regards,

DG.

Locked