List of usage examples for org.jfree.data.time TimeSeries add
public void add(RegularTimePeriod period, Number value)
From source file:com.sigueros.charts.LinearRegressionExample.java
/** * Creates a sample dataset for Linear data *///from w ww . ja va2 s . c o m private TimeSeriesCollection createDatasetLinear() { final TimeSeries linearData = new TimeSeries("Linear"); //The Linear dataSet is the Linear Regression: double ad[] = Regression.getOLSRegression(getData()); for (int i = 0; i < getData().length; i++) { //The formula to calculate the value is a + b * x, where a = ad[0] and b = ad [1] linearData.add(new Year((int) getData()[i][0]), ad[0] + ad[1] * getData()[i][0]); } TimeSeriesCollection dataLinearCollection = new TimeSeriesCollection(); dataLinearCollection.addSeries(linearData); return dataLinearCollection; }
From source file:graficoComparacion.graficaCompa.java
public void graficaCompa2() { //sxy.add(x[0], y[0]); TimeSeries s2 = new TimeSeries("Entrenamiento Actual"); /////////////// s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); ////////////////////////////////////// datos.addSeries(s2);//from ww w .ja va 2 s. c om }
From source file:graficoComparacion.graficaCompa.java
public void grafica1() { s1.add(new Month(4, 2001), 153.8); s1.add(new Month(5, 2001), 167.6); s1.add(new Month(6, 2001), 158.8); s1.add(new Month(7, 2001), 148.3); s1.add(new Month(8, 2001), 153.9); s1.add(new Month(9, 2001), 142.7); s1.add(new Month(10, 2001), 123.2); s1.add(new Month(11, 2001), 131.8); s1.add(new Month(12, 2001), 139.6); s1.add(new Month(1, 2002), 142.9); s1.add(new Month(2, 2002), 138.7); s1.add(new Month(3, 2002), 137.3); s1.add(new Month(4, 2002), 143.9); s1.add(new Month(5, 2002), 139.8); s1.add(new Month(6, 2002), 137.0); s1.add(new Month(7, 2002), 132.8); TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); s2.add(new Month(2, 2001), 129.6); s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); s2.add(new Month(11, 2001), 106.1); s2.add(new Month(12, 2001), 110.3); s2.add(new Month(1, 2002), 111.7); s2.add(new Month(2, 2002), 111.0); s2.add(new Month(3, 2002), 109.6); s2.add(new Month(4, 2002), 113.2); s2.add(new Month(5, 2002), 111.6); s2.add(new Month(6, 2002), 108.8); s2.add(new Month(7, 2002), 101.6); TimeSeries s3 = new TimeSeries("andres2255"); s3.add(new Month(2, 2001), 129.6); s3.add(new Month(10, 2001), 106.1); s3.add(new Month(1, 2002), 111.7); s3.add(new Month(2, 2002), 111.0); datos.addSeries(s1);/*from w w w . j ava 2 s .c o m*/ datos.addSeries(s2); datos.addSeries(s3); }
From source file:msec.org.Tools.java
private static XYDataset createDaysDataset(ArrayList<OneDayValue> oneDayValues, GregorianCalendar startgc, OneAttrDaysChart chart) {/*from w w w . j a va2 s. c o m*/ TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); TimeSeries timeseries = new TimeSeries( oneDayValues.get(0).getDate() + "-" + oneDayValues.get(oneDayValues.size() - 1).getDate()); int sum = 0; int max = 0; int min = 0; Minute current = new Minute(startgc.getTime()); for (int j = 0; j < oneDayValues.size(); j++) { int[] data = oneDayValues.get(j).getValues(); //check actual length for data int len = data.length - 1; if (j == oneDayValues.size() - 1) { //if last day is today... if (oneDayValues.get(j).getDate().equals(Tools.nowString("yyyyMMdd"))) { for (int i = len; i >= 0; i--) { if (data[i] != 0) { len = i; break; } } } } for (int i = 0; i < len; ++i) { timeseries.add(current, (double) (data[i])); sum += data[i]; max = Math.max(max, data[i]); if (min == 0) min = data[i]; else if (data[i] != 0) min = Math.min(min, data[i]); current = (Minute) current.next(); } } chart.setMax(max); chart.setMin(min); chart.setSum(sum); timeseriescollection.addSeries(timeseries); return timeseriescollection; }
From source file:org.jfree.chart.demo.DifferenceChartDemo.java
/** * Creates a new demo./*from www . ja va2s.c om*/ * * @param title the frame title. */ public DifferenceChartDemo(final String title) { super(title); final TimeSeries series1 = new TimeSeries("Random 1"); final TimeSeries series2 = new TimeSeries("Random 2"); double value1 = 0.0; double value2 = 0.0; Day day = new Day(); for (int i = 0; i < 200; i++) { value1 = value1 + Math.random() - 0.5; value2 = value2 + Math.random() - 0.5; series1.add(day, value1); series2.add(day, value2); day = (Day) day.next(); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:com.stableapps.anglewraparounddemo.AngleWrapDemoMain.java
/** * Creates a sample dataset.//from ww w.j a va 2 s.co m * * @param count the item count. * * @return the dataset. */ private XYDataset createAngleDataset(final int count) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); final TimeSeries s1 = new TimeSeries("Angle (In Degrees)"); RegularTimePeriod start = new Minute(); double direction = 180.0; for (int i = 0; i < count; i++) { s1.add(start, direction); start = start.next(); direction = direction + (Math.random() - 0.45) * 15.0; if (direction < 0.0) { direction = direction + 360.0; } else if (direction > 360.0) { direction = direction - 360.0; } } dataset.addSeries(s1); return dataset; }
From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java
/** * The resulting chart consists a TimeSeries for each FeatureOfInterest contained in the * observationCollection.//ww w. j av a 2 s. com * * @param foiIdArray * the IDs of the FeaturesOfInterest whose Observations shall be rendered * @param observationCollection * @return */ protected XYPlot drawChart4FOI(String foiID, Map<ITimePosition, ObservedValueTuple> timeMap) { TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries timeSeries = new TimeSeries(foiID, Second.class); for (ITimePosition timePos : timeMap.keySet()) { Number value = (Number) timeMap.get(timePos).getValue(0); timeSeries.add( new Second(new Float(timePos.getSecond()).intValue(), timePos.getMinute(), timePos.getHour(), timePos.getDay(), timePos.getMonth(), new Long(timePos.getYear()).intValue()), value); } dataset.addSeries(timeSeries); dataset.setDomainIsPointsInTime(true); // // create Plot: // XYPlot plot = new XYPlot(); plot.setDataset(dataset); plot.setBackgroundPaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); plot.setRenderer(renderer); DateAxis dateAxis = new DateAxis(); dateAxis.setTickMarkPosition(DateTickMarkPosition.START); dateAxis.setTickMarksVisible(true); dateAxis.setVerticalTickLabels(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("dd'.'MM'.'")); plot.setDomainAxis(dateAxis); plot.setRangeAxis(new NumberAxis()); return plot; }
From source file:edu.ucla.stat.SOCR.chart.demo.XYAreaChartDemo2.java
protected XYDataset createDataset(boolean isDemo) { if (isDemo) { TimeSeries series1 = new TimeSeries("Random 1"); double value = 0.0; Day day = new Day(); for (int i = 0; i < 200; i++) { value = value + Math.random() - 0.5; series1.add(day, value); day = (Day) day.next();//from w w w. j a v a 2s .co m } TimeSeriesCollection dataset = new TimeSeriesCollection(series1); return dataset; } else { setArrayFromTable(); if (independentVarLength != dependentVarLength) { JOptionPane.showMessageDialog(this, "The number of X and Y doesn't match!"); resetChart(); return null; } String[][] x = new String[xyLength][independentVarLength]; double[][] y = new double[xyLength][dependentVarLength]; int[][] skipy = new int[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) { if (depValues[i][index] == null || depValues[i][index].length() == 0) skipy[i][index] = 1; else y[i][index] = Double.parseDouble(depValues[i][index]); } TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries series; for (int i = 0; i < independentVarLength; i++) { String serieName = independentHeaders[i]; if (independentHeaders[i].lastIndexOf(":") != -1) serieName = independentHeaders[i].substring(0, independentHeaders[i].lastIndexOf(":")); series = new TimeSeries(serieName); for (int j = 0; j < xyLength; j++) { if (x[j][i] != null && skipy[j][i] != 1) series.add(DateParser.parseDay(x[j][i]), y[j][i]); //System.out.println("adding :("+x[j][i]+","+y[j][i]+","+independentHeaders[i]+")" ); } dataset.addSeries(series); } return dataset; } }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Creates a time series for testing./*w ww. java 2s . co m*/ * * @return A time series. */ private TimeSeries createSeries() { RegularTimePeriod t = new Day(); TimeSeries series = new TimeSeries("Test"); series.add(t, 1.0); t = t.next(); series.add(t, 2.0); t = t.next(); series.add(t, null); t = t.next(); series.add(t, 4.0); return series; }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Basic checks for cloning.//from ww w.j a va 2s. co m */ @Test public void testCloning() throws CloneNotSupportedException { TimeSeries s1 = new TimeSeries("Series"); s1.add(new Year(2009), 1.1); TimeSeriesCollection c1 = new TimeSeriesCollection(); c1.addSeries(s1); TimeSeriesCollection c2 = (TimeSeriesCollection) c1.clone(); assertTrue(c1 != c2); assertTrue(c1.getClass() == c2.getClass()); assertTrue(c1.equals(c2)); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); c2.getSeries(0).setDescription("XYZ"); assertTrue(c1.equals(c2)); }