How to construct and use TimeSeriesCollections

家住魔仙堡 提交于 2019-12-08 00:44:31

问题


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


回答1:


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"));


来源:https://stackoverflow.com/questions/5119244/how-to-construct-and-use-timeseriescollections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!