How to construct and use TimeSeriesCollections
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
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"));
精彩评论