List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name)
From source file:gui.DemoDatasetFactory.java
/** * Returns a time series of the daily USD/GBP exchange rates in 2001 (to date), for use in * the JFreeChart demonstration application. * <P>/*from www. j av a 2 s.co m*/ * You wouldn't normally create a time series in this way. Typically, values would * be read from a database. * * @return a time series. * */ public static TimeSeries createUSDTimeSeries() { TimeSeries t1 = new TimeSeries("USD/GBP"); try { t1.add(new Day(2, MonthConstants.JANUARY, 2001), 1.4956); t1.add(new Day(3, MonthConstants.JANUARY, 2001), new Double(1.5047)); t1.add(new Day(4, MonthConstants.JANUARY, 2001), new Double(1.4931)); t1.add(new Day(5, MonthConstants.JANUARY, 2001), new Double(1.4955)); t1.add(new Day(8, MonthConstants.JANUARY, 2001), new Double(1.4994)); t1.add(new Day(9, MonthConstants.JANUARY, 2001), new Double(1.4911)); t1.add(new Day(10, MonthConstants.JANUARY, 2001), new Double(1.4903)); t1.add(new Day(11, MonthConstants.JANUARY, 2001), new Double(1.4947)); t1.add(new Day(12, MonthConstants.JANUARY, 2001), new Double(1.4784)); t1.add(new Day(15, MonthConstants.JANUARY, 2001), new Double(1.4787)); t1.add(new Day(16, MonthConstants.JANUARY, 2001), new Double(1.4702)); t1.add(new Day(17, MonthConstants.JANUARY, 2001), new Double(1.4729)); t1.add(new Day(18, MonthConstants.JANUARY, 2001), new Double(1.4760)); t1.add(new Day(19, MonthConstants.JANUARY, 2001), new Double(1.4685)); t1.add(new Day(22, MonthConstants.JANUARY, 2001), new Double(1.4609)); t1.add(new Day(23, MonthConstants.JANUARY, 2001), new Double(1.4709)); t1.add(new Day(24, MonthConstants.JANUARY, 2001), new Double(1.4576)); t1.add(new Day(25, MonthConstants.JANUARY, 2001), new Double(1.4589)); t1.add(new Day(26, MonthConstants.JANUARY, 2001), new Double(1.4568)); t1.add(new Day(29, MonthConstants.JANUARY, 2001), new Double(1.4566)); t1.add(new Day(30, MonthConstants.JANUARY, 2001), new Double(1.4604)); t1.add(new Day(31, MonthConstants.JANUARY, 2001), new Double(1.4616)); t1.add(new Day(1, MonthConstants.FEBRUARY, 2001), new Double(1.4777)); t1.add(new Day(2, MonthConstants.FEBRUARY, 2001), new Double(1.4687)); t1.add(new Day(5, MonthConstants.FEBRUARY, 2001), new Double(1.4753)); t1.add(new Day(6, MonthConstants.FEBRUARY, 2001), new Double(1.4605)); t1.add(new Day(7, MonthConstants.FEBRUARY, 2001), new Double(1.4619)); t1.add(new Day(8, MonthConstants.FEBRUARY, 2001), new Double(1.4453)); t1.add(new Day(9, MonthConstants.FEBRUARY, 2001), new Double(1.4463)); t1.add(new Day(12, MonthConstants.FEBRUARY, 2001), new Double(1.4521)); t1.add(new Day(13, MonthConstants.FEBRUARY, 2001), new Double(1.4517)); t1.add(new Day(14, MonthConstants.FEBRUARY, 2001), new Double(1.4601)); t1.add(new Day(15, MonthConstants.FEBRUARY, 2001), new Double(1.4500)); t1.add(new Day(16, MonthConstants.FEBRUARY, 2001), new Double(1.4517)); t1.add(new Day(19, MonthConstants.FEBRUARY, 2001), new Double(1.4459)); t1.add(new Day(20, MonthConstants.FEBRUARY, 2001), new Double(1.4449)); t1.add(new Day(21, MonthConstants.FEBRUARY, 2001), new Double(1.4447)); t1.add(new Day(22, MonthConstants.FEBRUARY, 2001), new Double(1.4465)); t1.add(new Day(23, MonthConstants.FEBRUARY, 2001), new Double(1.4487)); t1.add(new Day(26, MonthConstants.FEBRUARY, 2001), new Double(1.4417)); t1.add(new Day(27, MonthConstants.FEBRUARY, 2001), new Double(1.4420)); t1.add(new Day(28, MonthConstants.FEBRUARY, 2001), new Double(1.4421)); t1.add(new Day(1, MonthConstants.MARCH, 2001), new Double(1.4547)); t1.add(new Day(2, MonthConstants.MARCH, 2001), new Double(1.4741)); t1.add(new Day(5, MonthConstants.MARCH, 2001), new Double(1.4686)); t1.add(new Day(6, MonthConstants.MARCH, 2001), new Double(1.4667)); t1.add(new Day(7, MonthConstants.MARCH, 2001), new Double(1.4618)); t1.add(new Day(8, MonthConstants.MARCH, 2001), new Double(1.4685)); t1.add(new Day(9, MonthConstants.MARCH, 2001), new Double(1.4677)); t1.add(new Day(12, MonthConstants.MARCH, 2001), new Double(1.4660)); t1.add(new Day(13, MonthConstants.MARCH, 2001), new Double(1.4526)); t1.add(new Day(14, MonthConstants.MARCH, 2001), new Double(1.4483)); t1.add(new Day(15, MonthConstants.MARCH, 2001), new Double(1.4441)); t1.add(new Day(16, MonthConstants.MARCH, 2001), new Double(1.4303)); t1.add(new Day(19, MonthConstants.MARCH, 2001), new Double(1.4259)); t1.add(new Day(20, MonthConstants.MARCH, 2001), new Double(1.4283)); t1.add(new Day(21, MonthConstants.MARCH, 2001), new Double(1.4293)); t1.add(new Day(22, MonthConstants.MARCH, 2001), new Double(1.4192)); t1.add(new Day(23, MonthConstants.MARCH, 2001), new Double(1.4293)); t1.add(new Day(26, MonthConstants.MARCH, 2001), new Double(1.4334)); t1.add(new Day(27, MonthConstants.MARCH, 2001), new Double(1.4371)); t1.add(new Day(28, MonthConstants.MARCH, 2001), new Double(1.4347)); t1.add(new Day(29, MonthConstants.MARCH, 2001), new Double(1.4362)); t1.add(new Day(30, MonthConstants.MARCH, 2001), new Double(1.4217)); t1.add(new Day(2, MonthConstants.APRIL, 2001), new Double(1.4205)); t1.add(new Day(3, MonthConstants.APRIL, 2001), new Double(1.4270)); t1.add(new Day(4, MonthConstants.APRIL, 2001), new Double(1.4333)); t1.add(new Day(5, MonthConstants.APRIL, 2001), new Double(1.4287)); t1.add(new Day(6, MonthConstants.APRIL, 2001), new Double(1.4395)); t1.add(new Day(9, MonthConstants.APRIL, 2001), new Double(1.4494)); t1.add(new Day(10, MonthConstants.APRIL, 2001), new Double(1.4385)); t1.add(new Day(11, MonthConstants.APRIL, 2001), new Double(1.4348)); t1.add(new Day(12, MonthConstants.APRIL, 2001), new Double(1.4402)); t1.add(new Day(17, MonthConstants.APRIL, 2001), new Double(1.4314)); t1.add(new Day(18, MonthConstants.APRIL, 2001), new Double(1.4197)); t1.add(new Day(19, MonthConstants.APRIL, 2001), new Double(1.4365)); t1.add(new Day(20, MonthConstants.APRIL, 2001), new Double(1.4416)); t1.add(new Day(23, MonthConstants.APRIL, 2001), new Double(1.4396)); t1.add(new Day(24, MonthConstants.APRIL, 2001), new Double(1.4360)); t1.add(new Day(25, MonthConstants.APRIL, 2001), new Double(1.4397)); t1.add(new Day(26, MonthConstants.APRIL, 2001), new Double(1.4402)); t1.add(new Day(27, MonthConstants.APRIL, 2001), new Double(1.4366)); t1.add(new Day(30, MonthConstants.APRIL, 2001), new Double(1.4309)); t1.add(new Day(1, MonthConstants.MAY, 2001), new Double(1.4324)); t1.add(new Day(2, MonthConstants.MAY, 2001), new Double(1.4336)); t1.add(new Day(3, MonthConstants.MAY, 2001), new Double(1.4329)); t1.add(new Day(4, MonthConstants.MAY, 2001), new Double(1.4375)); t1.add(new Day(8, MonthConstants.MAY, 2001), new Double(1.4321)); t1.add(new Day(9, MonthConstants.MAY, 2001), new Double(1.4219)); t1.add(new Day(10, MonthConstants.MAY, 2001), new Double(1.4226)); t1.add(new Day(11, MonthConstants.MAY, 2001), new Double(1.4199)); t1.add(new Day(14, MonthConstants.MAY, 2001), new Double(1.4183)); t1.add(new Day(15, MonthConstants.MAY, 2001), new Double(1.4218)); t1.add(new Day(16, MonthConstants.MAY, 2001), new Double(1.4295)); t1.add(new Day(17, MonthConstants.MAY, 2001), new Double(1.4296)); t1.add(new Day(18, MonthConstants.MAY, 2001), new Double(1.4296)); t1.add(new Day(21, MonthConstants.MAY, 2001), new Double(1.4366)); t1.add(new Day(22, MonthConstants.MAY, 2001), new Double(1.4283)); t1.add(new Day(23, MonthConstants.MAY, 2001), new Double(1.4244)); t1.add(new Day(24, MonthConstants.MAY, 2001), new Double(1.4102)); t1.add(new Day(25, MonthConstants.MAY, 2001), new Double(1.4205)); t1.add(new Day(29, MonthConstants.MAY, 2001), new Double(1.4183)); t1.add(new Day(30, MonthConstants.MAY, 2001), new Double(1.4230)); t1.add(new Day(31, MonthConstants.MAY, 2001), new Double(1.4201)); t1.add(new Day(1, MonthConstants.JUNE, 2001), new Double(1.4148)); t1.add(new Day(4, MonthConstants.JUNE, 2001), new Double(1.4142)); t1.add(new Day(5, MonthConstants.JUNE, 2001), new Double(1.4095)); t1.add(new Day(6, MonthConstants.JUNE, 2001), new Double(1.3938)); t1.add(new Day(7, MonthConstants.JUNE, 2001), new Double(1.3886)); t1.add(new Day(8, MonthConstants.JUNE, 2001), new Double(1.3798)); t1.add(new Day(11, MonthConstants.JUNE, 2001), new Double(1.3726)); t1.add(new Day(12, MonthConstants.JUNE, 2001), new Double(1.3788)); t1.add(new Day(13, MonthConstants.JUNE, 2001), new Double(1.3878)); t1.add(new Day(14, MonthConstants.JUNE, 2001), new Double(1.4002)); t1.add(new Day(15, MonthConstants.JUNE, 2001), new Double(1.4033)); t1.add(new Day(18, MonthConstants.JUNE, 2001), new Double(1.4038)); t1.add(new Day(19, MonthConstants.JUNE, 2001), new Double(1.4023)); t1.add(new Day(20, MonthConstants.JUNE, 2001), new Double(1.3952)); t1.add(new Day(21, MonthConstants.JUNE, 2001), new Double(1.4142)); t1.add(new Day(22, MonthConstants.JUNE, 2001), new Double(1.4114)); t1.add(new Day(25, MonthConstants.JUNE, 2001), new Double(1.4141)); t1.add(new Day(26, MonthConstants.JUNE, 2001), new Double(1.4157)); t1.add(new Day(27, MonthConstants.JUNE, 2001), new Double(1.4136)); t1.add(new Day(28, MonthConstants.JUNE, 2001), new Double(1.4089)); t1.add(new Day(29, MonthConstants.JUNE, 2001), new Double(1.4066)); t1.add(new Day(2, MonthConstants.JULY, 2001), new Double(1.4154)); t1.add(new Day(3, MonthConstants.JULY, 2001), new Double(1.4072)); t1.add(new Day(4, MonthConstants.JULY, 2001), new Double(1.4064)); t1.add(new Day(5, MonthConstants.JULY, 2001), new Double(1.3995)); t1.add(new Day(6, MonthConstants.JULY, 2001), new Double(1.4070)); t1.add(new Day(9, MonthConstants.JULY, 2001), new Double(1.4094)); t1.add(new Day(10, MonthConstants.JULY, 2001), new Double(1.4113)); t1.add(new Day(11, MonthConstants.JULY, 2001), new Double(1.4143)); t1.add(new Day(12, MonthConstants.JULY, 2001), new Double(1.4061)); t1.add(new Day(13, MonthConstants.JULY, 2001), new Double(1.4008)); t1.add(new Day(16, MonthConstants.JULY, 2001), new Double(1.3999)); t1.add(new Day(17, MonthConstants.JULY, 2001), new Double(1.4003)); t1.add(new Day(18, MonthConstants.JULY, 2001), new Double(1.4155)); t1.add(new Day(19, MonthConstants.JULY, 2001), new Double(1.4165)); t1.add(new Day(20, MonthConstants.JULY, 2001), new Double(1.4282)); t1.add(new Day(23, MonthConstants.JULY, 2001), new Double(1.4190)); t1.add(new Day(24, MonthConstants.JULY, 2001), new Double(1.4200)); t1.add(new Day(25, MonthConstants.JULY, 2001), new Double(1.4276)); t1.add(new Day(26, MonthConstants.JULY, 2001), new Double(1.4275)); t1.add(new Day(27, MonthConstants.JULY, 2001), new Double(1.4233)); t1.add(new Day(30, MonthConstants.JULY, 2001), new Double(1.4246)); t1.add(new Day(31, MonthConstants.JULY, 2001), new Double(1.4254)); t1.add(new Day(1, MonthConstants.AUGUST, 2001), new Double(1.4319)); t1.add(new Day(2, MonthConstants.AUGUST, 2001), new Double(1.4321)); t1.add(new Day(3, MonthConstants.AUGUST, 2001), new Double(1.4293)); t1.add(new Day(6, MonthConstants.AUGUST, 2001), new Double(1.4190)); t1.add(new Day(7, MonthConstants.AUGUST, 2001), new Double(1.4176)); t1.add(new Day(8, MonthConstants.AUGUST, 2001), new Double(1.4139)); t1.add(new Day(9, MonthConstants.AUGUST, 2001), new Double(1.4214)); t1.add(new Day(10, MonthConstants.AUGUST, 2001), new Double(1.4266)); t1.add(new Day(11, MonthConstants.AUGUST, 2001), new Double(1.4220)); t1.add(new Day(12, MonthConstants.AUGUST, 2001), new Double(1.4210)); t1.add(new Day(15, MonthConstants.AUGUST, 2001), new Double(1.4383)); t1.add(new Day(16, MonthConstants.AUGUST, 2001), new Double(1.4431)); t1.add(new Day(17, MonthConstants.AUGUST, 2001), new Double(1.4445)); t1.add(new Day(20, MonthConstants.AUGUST, 2001), new Double(1.4444)); t1.add(new Day(21, MonthConstants.AUGUST, 2001), new Double(1.4483)); t1.add(new Day(22, MonthConstants.AUGUST, 2001), new Double(1.4556)); t1.add(new Day(23, MonthConstants.AUGUST, 2001), new Double(1.4468)); t1.add(new Day(24, MonthConstants.AUGUST, 2001), new Double(1.4464)); t1.add(new Day(28, MonthConstants.AUGUST, 2001), new Double(1.4483)); t1.add(new Day(29, MonthConstants.AUGUST, 2001), new Double(1.4519)); t1.add(new Day(30, MonthConstants.AUGUST, 2001), new Double(1.4494)); t1.add(new Day(31, MonthConstants.AUGUST, 2001), new Double(1.4505)); t1.add(new Day(3, MonthConstants.SEPTEMBER, 2001), new Double(1.4519)); t1.add(new Day(4, MonthConstants.SEPTEMBER, 2001), new Double(1.4460)); t1.add(new Day(5, MonthConstants.SEPTEMBER, 2001), new Double(1.4526)); t1.add(new Day(6, MonthConstants.SEPTEMBER, 2001), new Double(1.4527)); t1.add(new Day(7, MonthConstants.SEPTEMBER, 2001), new Double(1.4617)); t1.add(new Day(10, MonthConstants.SEPTEMBER, 2001), new Double(1.4583)); t1.add(new Day(11, MonthConstants.SEPTEMBER, 2001), new Double(1.4693)); t1.add(new Day(12, MonthConstants.SEPTEMBER, 2001), new Double(1.4633)); t1.add(new Day(13, MonthConstants.SEPTEMBER, 2001), new Double(1.4690)); t1.add(new Day(14, MonthConstants.SEPTEMBER, 2001), new Double(1.4691)); t1.add(new Day(17, MonthConstants.SEPTEMBER, 2001), new Double(1.4668)); t1.add(new Day(18, MonthConstants.SEPTEMBER, 2001), new Double(1.4624)); t1.add(new Day(19, MonthConstants.SEPTEMBER, 2001), new Double(1.4678)); t1.add(new Day(20, MonthConstants.SEPTEMBER, 2001), new Double(1.4657)); t1.add(new Day(21, MonthConstants.SEPTEMBER, 2001), new Double(1.4575)); t1.add(new Day(24, MonthConstants.SEPTEMBER, 2001), new Double(1.4646)); t1.add(new Day(25, MonthConstants.SEPTEMBER, 2001), new Double(1.4699)); t1.add(new Day(26, MonthConstants.SEPTEMBER, 2001), new Double(1.4749)); t1.add(new Day(27, MonthConstants.SEPTEMBER, 2001), new Double(1.4756)); t1.add(new Day(28, MonthConstants.SEPTEMBER, 2001), new Double(1.4699)); t1.add(new Day(1, MonthConstants.OCTOBER, 2001), new Double(1.4784)); t1.add(new Day(2, MonthConstants.OCTOBER, 2001), new Double(1.4661)); t1.add(new Day(3, MonthConstants.OCTOBER, 2001), new Double(1.4767)); t1.add(new Day(4, MonthConstants.OCTOBER, 2001), new Double(1.4770)); t1.add(new Day(5, MonthConstants.OCTOBER, 2001), new Double(1.4810)); t1.add(new Day(8, MonthConstants.OCTOBER, 2001), new Double(1.4743)); t1.add(new Day(9, MonthConstants.OCTOBER, 2001), new Double(1.4667)); t1.add(new Day(10, MonthConstants.OCTOBER, 2001), new Double(1.4505)); t1.add(new Day(11, MonthConstants.OCTOBER, 2001), new Double(1.4434)); t1.add(new Day(12, MonthConstants.OCTOBER, 2001), new Double(1.4504)); t1.add(new Day(15, MonthConstants.OCTOBER, 2001), new Double(1.4471)); t1.add(new Day(16, MonthConstants.OCTOBER, 2001), new Double(1.4474)); t1.add(new Day(17, MonthConstants.OCTOBER, 2001), new Double(1.4512)); t1.add(new Day(18, MonthConstants.OCTOBER, 2001), new Double(1.4445)); t1.add(new Day(19, MonthConstants.OCTOBER, 2001), new Double(1.4384)); t1.add(new Day(22, MonthConstants.OCTOBER, 2001), new Double(1.4275)); t1.add(new Day(23, MonthConstants.OCTOBER, 2001), new Double(1.4212)); t1.add(new Day(24, MonthConstants.OCTOBER, 2001), new Double(1.4233)); t1.add(new Day(25, MonthConstants.OCTOBER, 2001), new Double(1.4297)); t1.add(new Day(26, MonthConstants.OCTOBER, 2001), new Double(1.4328)); t1.add(new Day(29, MonthConstants.OCTOBER, 2001), new Double(1.4515)); t1.add(new Day(30, MonthConstants.OCTOBER, 2001), new Double(1.4564)); t1.add(new Day(31, MonthConstants.OCTOBER, 2001), new Double(1.4541)); t1.add(new Day(1, MonthConstants.NOVEMBER, 2001), new Double(1.4624)); t1.add(new Day(2, MonthConstants.NOVEMBER, 2001), new Double(1.4632)); t1.add(new Day(5, MonthConstants.NOVEMBER, 2001), new Double(1.4570)); t1.add(new Day(6, MonthConstants.NOVEMBER, 2001), new Double(1.4588)); t1.add(new Day(7, MonthConstants.NOVEMBER, 2001), new Double(1.4646)); t1.add(new Day(8, MonthConstants.NOVEMBER, 2001), new Double(1.4552)); t1.add(new Day(9, MonthConstants.NOVEMBER, 2001), new Double(1.4579)); t1.add(new Day(12, MonthConstants.NOVEMBER, 2001), new Double(1.4575)); t1.add(new Day(13, MonthConstants.NOVEMBER, 2001), new Double(1.4429)); t1.add(new Day(14, MonthConstants.NOVEMBER, 2001), new Double(1.4425)); t1.add(new Day(15, MonthConstants.NOVEMBER, 2001), new Double(1.4318)); t1.add(new Day(16, MonthConstants.NOVEMBER, 2001), new Double(1.4291)); t1.add(new Day(19, MonthConstants.NOVEMBER, 2001), new Double(1.4140)); t1.add(new Day(20, MonthConstants.NOVEMBER, 2001), new Double(1.4173)); t1.add(new Day(21, MonthConstants.NOVEMBER, 2001), new Double(1.4132)); t1.add(new Day(22, MonthConstants.NOVEMBER, 2001), new Double(1.4131)); t1.add(new Day(23, MonthConstants.NOVEMBER, 2001), new Double(1.4083)); t1.add(new Day(26, MonthConstants.NOVEMBER, 2001), new Double(1.4122)); t1.add(new Day(27, MonthConstants.NOVEMBER, 2001), new Double(1.4136)); t1.add(new Day(28, MonthConstants.NOVEMBER, 2001), new Double(1.4239)); t1.add(new Day(29, MonthConstants.NOVEMBER, 2001), new Double(1.4225)); t1.add(new Day(30, MonthConstants.NOVEMBER, 2001), new Double(1.4260)); } catch (Exception e) { System.err.println(e.getMessage()); } return t1; }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Basic tests for the delete() method./*from ww w . j av a 2 s .c o m*/ */ public void testDelete2() { TimeSeries s1 = new TimeSeries("Series"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.addChangeListener(this); this.gotSeriesChangeEvent = false; s1.delete(new Year(2001)); assertTrue(this.gotSeriesChangeEvent); assertEquals(2, s1.getItemCount()); assertEquals(null, s1.getValue(new Year(2001))); // try deleting a time period that doesn't exist... this.gotSeriesChangeEvent = false; s1.delete(new Year(2006)); assertFalse(this.gotSeriesChangeEvent); // try deleting null try { s1.delete(null); fail("Expected IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly when there is a * maximum item count and a new value is added. *//*from w w w . j a va 2 s. co m*/ @Test public void testDelete_RegularTimePeriod() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 4.4); s1.delete(new Year(2010)); s1.delete(new Year(2013)); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:de.fau.amos.ChartRenderer.java
/** * // w w w.ja va2 s. c o m * Creates TimeSeriesCollection by querying energy data from database. * * @param granularity Accuracy of distinguishment of displayed values (Summarise data to hours, days, months, years). * @param startTime Start of queried period. * @param endTime End of queried period. * @param sumOrAvg Shall values be added or averaged. * @param groupParameters Controlpoints that are affected. * @param unit Sets Unit (kWh or kWh/TNF) * @return TimeSeriesCollection that privedes the basis for creation of a png-chart */ private TimeSeriesCollection createTimeCollection(String granularity, String startTime, String endTime, String sumOrAvg, String groupParameters, String unit) { //time series containing all data TimeSeriesCollection collection = new TimeSeriesCollection(); //split groupParameter string to get all queryed groups seperated groupParameters = groupParameters.replace("||", "splitHere"); String[] groups = groupParameters.split("splitHere"); //handle groups one after another for (int i = 0; i < groups.length; i++) { //get group name String groupName = groups[i].contains("'") ? groups[i].substring(0, groups[i].indexOf("'")) : groups[i]; groups[i] = groups[i].contains("'") ? groups[i].substring(groupName.length()) : ""; if (!groups[i].contains("|")) { continue; } //get used plants String plants = groups[i].substring(groups[i].indexOf("|") + 1); //prepare queryString groups[i] = groups[i].substring(0, groups[i].indexOf("|")); //generate series for group TimeSeries series = new TimeSeries(groupName); ResultSet rs = null; //skip group if nothing is selected to query if (groups[i].trim() != "") { if ("1".equals(unit)) { //query kWh rs = SQL.queryToResultSet("select * from (select round(" + sumOrAvg + "(gruppenWert),4), gruppenZeit from(select " + sumOrAvg + "(wert) as gruppenWert,control_point_name, zeit1 as gruppenZeit from (select " + sumOrAvg + "(value)as wert,control_point_name,date_trunc('" + granularity + "',measure_time)as zeit1 from measures inner join controlpoints on measures.controlpoint_id=controlpoints.controlpoints_id where measure_time >= '" + startTime + "' AND measure_time < '" + endTime + "' AND controlpoints_id in(" + groups[i] + ") group by measure_time,control_point_name)as data group by zeit1,control_point_name)as groupedByTime group by gruppenZeit)as result order by gruppenZeit" + ";"); } else if ("2".equals(unit)) { //query kWh/TNF (only as sum, not avg) rs = SQL.queryToResultSet( "select * from (select round(sum(gruppenWert)/(select sum(am) from(select sum(amount)as am,date_trunc('" + granularity + "',measure_time)as zeit from productiondata inner join controlpoints on productiondata.controlpoint_id=controlpoints.controlpoints_id " + "where productiondata.measure_time >= '" + startTime + "' AND productiondata.measure_time < '" + endTime + "' AND reference_point='t' AND plant_id in(" + plants + ") group by measure_time)as wat where zeit=gruppenZeit group by zeit order by zeit),4), gruppenZeit from(" + "select sum(wert) as gruppenWert,control_point_name, zeit1 as gruppenZeit from (select sum(value)as wert,control_point_name,date_trunc('" + granularity + "',measure_time)as zeit1 from measures inner join controlpoints on measures.controlpoint_id=controlpoints.controlpoints_id where measure_time >= '" + startTime + "' AND measure_time < '" + endTime + "' AND controlpoints_id in(" + groups[i] + ")group by measure_time,control_point_name)as data group by zeit1,control_point_name)as groupedByTime group by gruppenZeit)as result order by gruppenZeit" + ";"); } } if (rs != null) { try { while (rs.next()) { switch (granularity) { case "minute": series.add(new Minute(Integer.parseInt(rs.getString(2).substring(14, 16)), Integer.parseInt(rs.getString(2).substring(11, 13)), Integer.parseInt(rs.getString(2).substring(8, 10)), Integer.parseInt(rs.getString(2).substring(5, 7)), Integer.parseInt(rs.getString(2).substring(0, 4))), rs.getDouble(1)); break; case "day": series.add(new Day(Integer.parseInt(rs.getString(2).substring(8, 10)), Integer.parseInt(rs.getString(2).substring(5, 7)), Integer.parseInt(rs.getString(2).substring(0, 4))), rs.getDouble(1)); break; case "month": series.add(new Month(Integer.parseInt(rs.getString(2).substring(5, 7)), Integer.parseInt(rs.getString(2).substring(0, 4))), rs.getDouble(1)); break; case "year": series.add(new Year(Integer.parseInt(rs.getString(2).substring(0, 4))), rs.getDouble(1)); break; //default: day default: series.add(new Day(Integer.parseInt(rs.getString(2).substring(8, 10)), Integer.parseInt(rs.getString(2).substring(5, 7)), Integer.parseInt(rs.getString(2).substring(0, 4))), rs.getDouble(1)); } } rs.close(); } catch (NumberFormatException e) { } catch (SQLException e) { e.printStackTrace(); } } //Add the series to the collection collection.addSeries(series); } return collection; }
From source file:mekhq.gui.FinancesTab.java
private XYDataset setupFinanceDataset() { TimeSeries s1 = new TimeSeries("C-Bills"); // NOI18N ArrayList<Transaction> transactions = getCampaign().getFinances().getAllTransactions(); Calendar cal = Calendar.getInstance(); long balance = 0; for (int i = 0; i < transactions.size(); i++) { balance += transactions.get(i).getAmount(); cal.setTime(transactions.get(i).getDate()); // since there may be more than one entry per day and the dataset for the graph can only have one entry per day // we use addOrUpdate() which assumes transactions are in sequential order by date so we always have the most // up-to-date entry for each day s1.addOrUpdate(new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, // Gregorian and Julian calendars start at 0: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#MONTH cal.get(Calendar.YEAR)), balance); }/*from w ww . j av a2s .c o m*/ TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void addSeries(TimeSeriesCollection chartSeries, TsData data) { TimeSeries chartTs = new TimeSeries(""); for (int i = 0; i < data.getDomain().getLength(); ++i) { if (DescriptiveStatistics.isFinite(data.get(i))) { Day day = new Day(data.getDomain().get(i).middle()); chartTs.addOrUpdate(day, data.get(i)); }//w w w.j a va2s. c o m } chartSeries.addSeries(chartTs); }
From source file:com.android.ddmuilib.net.NetworkPanel.java
/** * Create chart of recent network activity. *///from w w w.ja v a 2s . c o m private void createChart() { mChart = ChartFactory.createTimeSeriesChart(null, null, null, null, false, false, false); // create backing datasets and series mRxTotalSeries = new TimeSeries("RX total"); mTxTotalSeries = new TimeSeries("TX total"); mRxTotalSeries.setMaximumItemAge(HISTORY_MILLIS); mTxTotalSeries.setMaximumItemAge(HISTORY_MILLIS); mTotalCollection = new TimeSeriesCollection(); mTotalCollection.addSeries(mRxTotalSeries); mTotalCollection.addSeries(mTxTotalSeries); mRxDetailDataset = new LiveTimeTableXYDataset(); mTxDetailDataset = new LiveTimeTableXYDataset(); mTotalRenderer = new XYAreaRenderer(XYAreaRenderer.AREA); mRenderer = new StackedXYAreaRenderer2(); final XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); xyPlot.setDataset(0, mTotalCollection); xyPlot.setDataset(1, mRxDetailDataset); xyPlot.setDataset(2, mTxDetailDataset); xyPlot.setRenderer(0, mTotalRenderer); xyPlot.setRenderer(1, mRenderer); xyPlot.setRenderer(2, mRenderer); // we control domain axis manually when taking samples mDomainAxis = xyPlot.getDomainAxis(); mDomainAxis.setAutoRange(false); final NumberAxis axis = new NumberAxis(); axis.setNumberFormatOverride(new BytesFormat(true)); axis.setAutoRangeMinimumSize(50); xyPlot.setRangeAxis(axis); xyPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); // draw thick line to separate RX versus TX traffic xyPlot.addRangeMarker(new ValueMarker(0, java.awt.Color.BLACK, new java.awt.BasicStroke(2))); // label to indicate that positive axis is RX traffic final ValueMarker rxMarker = new ValueMarker(0); rxMarker.setStroke(new java.awt.BasicStroke(0)); rxMarker.setLabel("RX"); rxMarker.setLabelFont(rxMarker.getLabelFont().deriveFont(30f)); rxMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY); rxMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); rxMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); xyPlot.addRangeMarker(rxMarker); // label to indicate that negative axis is TX traffic final ValueMarker txMarker = new ValueMarker(0); txMarker.setStroke(new java.awt.BasicStroke(0)); txMarker.setLabel("TX"); txMarker.setLabelFont(txMarker.getLabelFont().deriveFont(30f)); txMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY); txMarker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); txMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); xyPlot.addRangeMarker(txMarker); mChartComposite = new ChartComposite(mPanel, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 4096, 4096, true, true, true, true, false, true); final FormData data = new FormData(); data.top = new FormAttachment(mHeader); data.left = new FormAttachment(0); data.bottom = new FormAttachment(70); data.right = new FormAttachment(100); mChartComposite.setLayoutData(data); }
From source file:org.mwc.asset.netasset2.sensor2.VSensor.java
private void processThis(final DetectionEvent thisD) { // keep track of if we need to add the time series to the plot boolean addDataset = false; if (dataList == null) { dataList = new TimeSeriesCollection(); addDataset = true;/* w ww . j a va 2 s .co m*/ } final String seriesId = "s" + thisD.getSensor() + "t" + thisD.getTarget(); TimeSeries thisSeries = dataList.getSeries(seriesId); // keep track of if we should be adding this series to the dataset boolean seriesAddPending = false; if (thisSeries == null) { thisSeries = new TimeSeries(seriesId); // don't actually add the series until it contains some data seriesAddPending = true; } float bearing = thisD.getBearing(); if (bearing < 0) bearing += 360; final long newTime = thisD.getTime(); final FixedMillisecond time = new FixedMillisecond(newTime); try { thisSeries.add(time, bearing); } catch (final Exception e) { System.err.println("BUGGER"); } if (seriesAddPending) dataList.addSeries(thisSeries); if (addDataset) _thePlot.setDataset(dataList); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from ww w . j ava 2 s . c o m*/ @Test public void testSerialization() { TimeSeries s1 = new TimeSeries("A test"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); TimeSeries s2 = (TimeSeries) TestUtilities.serialised(s1); assertTrue(s1.equals(s2)); }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void addStart(TimeSeriesCollection chartSeries, String name, TsPeriod start) { TsData ts = history_.series(name, start); if (ts != null) { TimeSeries chartTs = new TimeSeries(""); int pos = start.minus(ts.getStart()); Day day = new Day(start.middle()); chartTs.add(day, ts.get(pos));// w w w .j a v a 2s. c om chartSeries.addSeries(chartTs); } }