List of usage examples for org.jfree.data.time TimeSeries add
public void add(RegularTimePeriod period, Number value)
From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java
/** * Creates a random dataset.//from w w w .j ava 2 s . c o m * * @param name the series name. * * @return The dataset. */ private TimeSeriesCollection createRandomDataset(final String name) { final TimeSeries series = new TimeSeries(name); double value = 100.0; RegularTimePeriod t = new Day(); for (int i = 0; i < 50; i++) { series.add(t, value); t = t.next(); value = value * (1.0 + Math.random() / 100); } return new TimeSeriesCollection(series); }
From source file:com.continuent.bristlecone.evaluator.MovingAverageDemo.java
/** * Creates a dataset, one series containing unit trust prices, the other a * moving average./*from w ww . j a v a 2s . co m*/ * * @return The dataset. */ public XYDataset createDataset() { ArrayList<Double> s1 = new ArrayList<Double>(); s1.add(181.8); s1.add(167.3); s1.add(153.8); s1.add(167.6); s1.add(158.8); s1.add(148.3); s1.add(153.9); s1.add(142.7); s1.add(123.2); s1.add(131.8); s1.add(139.6); s1.add(142.9); s1.add(138.7); s1.add(137.3); s1.add(143.9); s1.add(139.8); s1.add(137.0); s1.add(132.8); TimeSeries series1 = new TimeSeries("L&G European Index Trust", Millisecond.class); try { for (Double val : s1) { Thread.sleep(10); series1.add(new Millisecond(), val); } } catch (InterruptedException i) { // } TimeSeries s2 = MovingAverage.createMovingAverage(series1, "Six Month Moving Average", 100, 0); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(s2); return dataset; }
From source file:cv.mikusher.freechart.TimeSeries_AWT.java
private XYDataset createDataset() { final TimeSeries series = new TimeSeries("Random Data"); Second current = new Second(); double value = 100.0; for (int i = 0; i < 4000; i++) { try {//from www. j a va2 s . co m value = value + Math.random() - 0.5; series.add(current, new Double(value)); current = (Second) current.next(); } catch (SeriesException e) { System.err.println("Error adding to series"); } } return new TimeSeriesCollection(series); }
From source file:net.sf.statcvs.output.xml.chart.TimeLineChart.java
void addTimeLine(TimeLine timeLine) { TimeSeries result = new TimeSeries(timeLine.getTitle(), Millisecond.class); Iterator it = timeLine.getDataPoints().iterator(); while (it.hasNext()) { TimePoint timePoint = (TimePoint) it.next(); result.add(new Millisecond(timePoint.getDate()), timePoint.getValue()); }/*from ww w . j av a 2 s . c o m*/ tsc.addSeries(result); }
From source file:org.jfree.chart.demo.XYAreaChartDemo2.java
/** * Creates a new demo.// w ww.j a v a 2s . c o m * * @param title the frame title. */ public XYAreaChartDemo2(final String title) { super(title); final 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(); } final TimeSeriesCollection dataset = new TimeSeriesCollection(series1); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.InternalFrameDemo.java
/** * Creates a sample dataset.//w w w. j a v a 2 s .c o m * * @param name the dataset name. * @param base the starting value. * @param start the starting period. * @param count the number of values to generate. * * @return The dataset. */ private XYDataset createDataset(final String name, final double base, final RegularTimePeriod start, final int count) { final TimeSeries series = new TimeSeries(name, start.getClass()); RegularTimePeriod period = start; double value = base; for (int i = 0; i < count; i++) { series.add(period, value); period = period.next(); value = value * (1 + (Math.random() - 0.495) / 10.0); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); return dataset; }
From source file:net.footballpredictions.footballstats.swing.LeaguePositionGraph.java
/** * Plot league positions by date./*from ww w .ja v a 2 s . c o m*/ */ public void updateGraph(Object[] teams, LeagueSeason data) { assert teams.length > 0 : "Must be at least one team selected."; TimeSeriesCollection dataSet = new TimeSeriesCollection(); for (Object team : teams) { String teamName = (String) team; TimeSeries positionSeries = new TimeSeries(teamName); SortedMap<Date, Integer> positions = data.getTeam(teamName).getLeaguePositions(); for (Map.Entry<Date, Integer> entry : positions.entrySet()) { positionSeries.add(new Day(entry.getKey()), entry.getValue()); } dataSet.addSeries(positionSeries); } JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // Title messageResources.getString("graphs.date"), messageResources.getString("combo.GraphType.LEAGUE_POSITION"), dataSet, true, // Legend. false, // Tooltips. false); // URLs. chart.getXYPlot().getRangeAxis().setInverted(true); chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getRangeAxis().setRangeWithMargins(1, data.getTeamNames().size()); chart.getLegend().setPosition(legendPosition); setChart(chart); }
From source file:com.elasticgrid.examples.video.components.WatchChart.java
public StreamResponse onChart(final int width, final int height, Object... rest) throws RemoteException, InterruptedException { String serviceID = (String) rest[2]; String watchID = (String) rest[3]; System.out.println("Service ID is: " + serviceID + ". Watch ID is: " + watchID); List<WatchDataSource> watches = ServiceLocator .getWatchDataSourcesByServiceID(ConfigUtil.createServiceID(serviceID)); WatchDataSource watch = null;/*www.j a v a 2 s.c om*/ for (WatchDataSource w : watches) { System.out.println("Testing with " + w.getID()); if (w.getID().equals(watchID)) watch = w; } if (watch == null) return null; TimeSeries s1 = new TimeSeries(watch.getID(), FixedMillisecond.class); for (Calculable calculable : watch.getCalculable()) s1.add(new FixedMillisecond(calculable.getWhen()), calculable.getValue()); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); final JFreeChart chart = ChartFactory.createTimeSeriesChart(watch.getID() + " Watch", // title "Date", // x-axis label "Value", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); return new StreamResponse() { public String getContentType() { return "image/png"; } public InputStream getStream() throws IOException { BufferedImage image = chart.createBufferedImage(width, height); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); ChartUtilities.writeBufferedImageAsPNG(byteArray, image); return new ByteArrayInputStream(byteArray.toByteArray()); } public void prepareResponse(Response response) { } }; }
From source file:finalproject.GraphData.java
/** * Creates a chart with the data that is graphed vs time * @param data//from w w w. j a va 2 s.c o m * @param names * @return */ public JFreeChart graphVsTime(String[][] data, String[] names) { TimeSeries mySeries = new TimeSeries("Data"); for (int i = 0; i < data.length; i++) { if (data[i][0] != null && data[i][1] != null) mySeries.add(new Hour(convertTime(data[i][0]), day), Integer.parseInt(data[i][1])); } TimeSeriesCollection collection = new TimeSeriesCollection(mySeries); XYDataset dataset = collection; JFreeChart chart = ChartFactory.createTimeSeriesChart("Blood Glucose vs Time", names[0], names[1], dataset, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo3.java
/** * Creates a sample dataset.// w w w . ja va 2 s .com */ protected IntervalXYDataset createDataset(boolean isDemo) { if (isDemo) { domainLabel = "Year"; rangeLabel = "Frequency"; chartTitle = "HistogramChartDemo3"; TimeSeries t1 = new TimeSeries("", "Year", "Frequency", Year.class); try { t1.add(new Year(1976), new Integer(0)); t1.add(new Year(1977), new Integer(1)); t1.add(new Year(1978), new Integer(0)); t1.add(new Year(1979), new Integer(2)); t1.add(new Year(1980), new Integer(0)); t1.add(new Year(1981), new Integer(1)); t1.add(new Year(1982), new Integer(2)); t1.add(new Year(1985), new Integer(18)); t1.add(new Year(1986), new Integer(18)); t1.add(new Year(1987), new Integer(25)); t1.add(new Year(1988), new Integer(11)); t1.add(new Year(1989), new Integer(16)); t1.add(new Year(1991), new Integer(14)); t1.add(new Year(1992), new Integer(31)); t1.add(new Year(1993), new Integer(38)); t1.add(new Year(1994), new Integer(31)); t1.add(new Year(1995), new Integer(56)); t1.add(new Year(1996), new Integer(45)); t1.add(new Year(1997), new Integer(74)); t1.add(new Year(1998), new Integer(68)); t1.add(new Year(1999), new Integer(98)); t1.add(new Year(2000), new Integer(85)); t1.add(new Year(2001), new Integer(66)); t1.add(new Year(2003), new Integer(65)); } catch (Exception e) { System.err.println(e.getMessage()); } TimeSeriesCollection tsc = new TimeSeriesCollection(t1); // tsc.setDomainIsPointsInTime(false); return tsc; } else return super.createDataset(false); }