Time Series Chart - values not lining up with tick marks

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
travis_cooper
Posts: 6
Joined: Thu Jul 17, 2008 3:57 pm
Location: Salt Lake City, Utah

Time Series Chart - values not lining up with tick marks

Post by travis_cooper » Thu Jul 17, 2008 4:42 pm

I tried searching through the forums for an answer to this question, but I haven't been able to find it. I am creating a time series chart and the points on the chart don't line up with the tick marks on my x-axis.

I tried to post a screen shot, but I guess I don't have enough posts to do that yet. Basically all the points for my values aren't lining up with the time tick marks. I think the problem is, that the chart is creating the tick marks on Mondays, but all my data is coming in as Sundays. So all the points are right before the actual tick mark. What is the best way for me to line these up? I noticed there is a way to clear out the tick marks, and then load in my own set, but I was hoping there might be a better way. Some of these charts might only have 5 different time points, others could have 60 or more. So I didn't want to have to write code to limit the number of tick marks if I don't have to.

Edited to add - My charts could also be fiscal periods, or quarters, and I see the same problem. With the periods the chart creates the tick marks for the first day of the month, but a fiscal period may not start on the first of the month.
Travis

travis_cooper
Posts: 6
Joined: Thu Jul 17, 2008 3:57 pm
Location: Salt Lake City, Utah

Post by travis_cooper » Thu Jul 17, 2008 9:01 pm

Okay, I ended up extending the DateAxis class and overrode the calculateLowestVisibleTickValue, nextStandardDate, and previousStandardDate methods. I also extended the DateTickUnit class and overrode pretty much every method. I still haven't done all the testing I need to on it, but it seems to be working. At least with small data sets everything seems to be lining up now. The only thing I'm anticipating is that I'm going to have to handle large datasets now. When the number of values in the series gets high I'm probably going to need to skip every other, or even more to get things to fit properly.

This is the best thing I could think of to solve the problem, does anybody have a better solution? Why doesn't the time series create the tick marks based on the time values in the dataset? If it did that I wouldn't have to do anything extra. Anyway, any other options would be appreciated. If not, at least I think I've got it working now.
Travis

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 » Thu Jul 17, 2008 10:17 pm

The DateAxis tick labelling does need some more options to enable some control over things like the day-of-the-week for labelling.
travis_cooper wrote:Why doesn't the time series create the tick marks based on the time values in the dataset? If it did that I wouldn't have to do anything extra.
Because the dataset interface (XYDataset) doesn't require any regularity in the x-values, even if *some* implementations (like TimeSeriesCollection) do impose some regularity. So if the DateAxis was to take all the x-values from the XYDataset, they might be bunched together and overlapping. So we use the same approach as the NumberAxis - provide labels at equally spaced intervals.

Of course, you can always override refreshTicks() and return whatever ticks you want.
David Gilbert
JFreeChart Project Leader

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

travis_cooper
Posts: 6
Joined: Thu Jul 17, 2008 3:57 pm
Location: Salt Lake City, Utah

Post by travis_cooper » Thu Jul 17, 2008 10:35 pm

Okay, thanks. I guess I will keep going down the path I started, it looks like it is the best way to handle this.
Travis

Locked