3

I want to display some dates in the X axis of a chart, and here it is said that i have to use a TimeSeriesCollections object

It seems that i have to add a TimeSeries to the TimeSeriesCollections, and that the TimeSeries has to be constructed using a RegularTimePeriod... I am a bit confused...

Can you please explain me what i have to do? If possible can you provide some example code? Thanks

Community
  • 1
  • 1
Maik
  • 811
  • 3
  • 22
  • 35

1 Answers1

5

TimeSeriesCollections are made up of TimeSeries objects

Use this method to add series to the dataset: addSeries(TimeSeries series)

When creating TimeSeries objects. Fill them with the time and values. Here is a rough example:

TimeSeries ts= new TimeSeries("Name of Series");
ts.addOrUpdate(new Year(2008), 42);
ts.addOrUpdate(new Year(2009), 51);
ts.addOrUpdate(new Year(2010), 97);
ts.addOrUpdate(new Year(2011), 45);

For getting the Axis to display the dates nicely, you will have to do something like this:

XYPlot plot = chart.getXYPlot();
DateAxis axis = new DateAxis();
plot.setDomainAxis(axis);
axis.setDateFormatOverride(new SimpleDateFormat("yyyy"));
jzd
  • 23,473
  • 9
  • 54
  • 76
  • There´s something wrong with that. In the chart the years are represented by some strange values (between 1.200.000.000.000 and 1.300.000.000.000). How can i for example insert a specific date instead of a year? – Maik Feb 25 '11 at 16:16
  • For a specific date use a different RegularTimePeriod class. I used Year in my example but you can use any of these: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/time/RegularTimePeriod.html – jzd Feb 25 '11 at 16:20
  • I have found the way to use a Day instead of a Year. But i still don't get what you wrote in the last code... What is that "plot"? – Maik Feb 28 '11 at 07:50
  • @Maik, Added the plot variable to the second example. – jzd Feb 28 '11 at 12:02