TimeSeries chart axis items are displayed multiple times

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
spennec
Posts: 6
Joined: Mon Jan 11, 2010 11:55 am
antibot: No, of course not.

TimeSeries chart axis items are displayed multiple times

Post by spennec » Mon Apr 19, 2010 1:31 pm

Hello,

I am creating a TimeSeries chart, based on a collection of dates and values. Then I print this chart to a PDF file. For this, I am using JFreeChart version 1.0.13.

The axis labels, on the date axis, are configured with the following pattern: "dd MMM", which prints dates like "14 Apr".

When I output the chart to the PDF, the horizontal axis displays dates like "12 Apr 12 Apr 13 Apr 13 Apr 14 Apr 14 Apr 15 Apr"... which is not really what I'd like to see ;-)

There is only one date-value pair for each day... If I print the same chart to a smaller image size, then the items appear once only.

If I add more values to the chart, then the dates are displayed correctly. It's only when there is few data to display that labels are doubled or tripled. What I'm guessing is that JFreeChart tries to keep the same distance between labels, and thus prints each label one more than once. I would have thought that, when there is few data, the framework just adds some distance between each labels...

Anybody knows how to change this behavior?

Thanks a lot :-)

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: TimeSeries chart axis items are displayed multiple times

Post by paradoxoff » Mon Apr 19, 2010 9:45 pm

There is no direct relationship between the number of data values and the number of tick labels. What is important is the range of the ValueAxis. By default, the ValueAxis will create as many tick labels as possible w/o tick label overlap to cover its value range.
Fortunately you can change the defaults. Try this:

Code: Select all

dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
This will force the ValueAxis to show one tick per day.

spennec
Posts: 6
Joined: Mon Jan 11, 2010 11:55 am
antibot: No, of course not.

Re: TimeSeries chart axis items are displayed multiple times

Post by spennec » Tue Apr 20, 2010 7:18 am

Thanks a lot paradoxoff!

That is right what I needed.

Locked