List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name)
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Common test setup.//from w ww . j a va 2 s . c o m */ @Before public void setUp() { this.seriesA = new TimeSeries("Series A"); this.seriesA.add(new Year(2000), new Integer(102000)); this.seriesA.add(new Year(2001), new Integer(102001)); this.seriesA.add(new Year(2002), new Integer(102002)); this.seriesA.add(new Year(2003), new Integer(102003)); this.seriesA.add(new Year(2004), new Integer(102004)); this.seriesA.add(new Year(2005), new Integer(102005)); this.seriesB = new TimeSeries("Series B"); this.seriesB.add(new Year(2006), new Integer(202006)); this.seriesB.add(new Year(2007), new Integer(202007)); this.seriesB.add(new Year(2008), new Integer(202008)); this.seriesC = new TimeSeries("Series C"); this.seriesC.add(new Year(1999), new Integer(301999)); this.seriesC.add(new Year(2000), new Integer(302000)); this.seriesC.add(new Year(2002), new Integer(302002)); }
From source file:de.citec.csra.allocation.vis.MovingChart.java
public MovingChart(final String title, int past, int future) { super(title); this.past = past; this.future = future; this.marker = new ValueMarker(System.currentTimeMillis()); marker.setPaint(Color.black); this.plustime = new TimeSeries("+" + future / 1000 + "s"); this.dataset.addSeries(this.plustime); this.chart = createChart(this.dataset); // this.timer.setInitialDelay(1000); this.plustime.addOrUpdate(new Millisecond(new Date(System.currentTimeMillis() - past)), 0); //Sets background color of chart chart.setBackgroundPaint(Color.LIGHT_GRAY); //Created JPanel to show graph on screen final JPanel content = new JPanel(new BorderLayout()); //Created Chartpanel for chart area final ChartPanel chartPanel = new ChartPanel(chart); //Added chartpanel to main panel content.add(chartPanel);//from w w w . j a va 2 s .c o m //Sets the size of whole window (JPanel) chartPanel.setPreferredSize(new java.awt.Dimension(1500, 600)); //Puts the whole content on a Frame setContentPane(content); XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) this.chart.getXYPlot().getRendererForDataset(dataset); r.setSeriesPaint(0, Color.BLACK); this.timer.start(); }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo1.java
/** * Creates a random dataset./*from w w w.j av a 2s . c om*/ * * @param name the series name. * * @return The dataset. */ private TimeSeriesCollection createRandomDataset(String name) { 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:org.tolven.analysis.bean.PercentTimeSeriesBean.java
private JFreeChart getChart(String dataSeriesTitle, String targetSeriesTitle, List<MenuData> snapshots, Date fromDate, Date toDate, Class<?> intervalUnitClass) { TimeSeries dataTimeSeries = new TimeSeries(dataSeriesTitle); TimeSeries targetTimeSeries = null;// w w w. j a va2 s. co m if (targetSeriesTitle != null) { targetTimeSeries = new TimeSeries(targetSeriesTitle); } for (MenuData snapshot : snapshots) { Date snapshotDate = snapshot.getDate01(); long nSnapshotresultsNumerator = snapshot.getLongField("normCount"); long nSnapshotresultsDenominator = snapshot.getLongField("allCount"); Double value = null; if (nSnapshotresultsDenominator == 0) { value = 0d; } else { value = 1d * nSnapshotresultsNumerator / nSnapshotresultsDenominator; } RegularTimePeriod regTimePeriod = RegularTimePeriod.createInstance(intervalUnitClass, snapshotDate, TimeZone.getDefault()); dataTimeSeries.addOrUpdate(regTimePeriod, value); if (targetTimeSeries != null) { Double targetPercent = snapshot.getDoubleField("targetPercent") / 100; targetTimeSeries.addOrUpdate(regTimePeriod, targetPercent); } } TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); timeSeriesCollection.addSeries(dataTimeSeries); if (targetTimeSeries != null) { timeSeriesCollection.addSeries(targetTimeSeries); } XYDataset xyDataset = (XYDataset) timeSeriesCollection; JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title null, // x-axis label null, // y-axis label xyDataset, // data true, // create legend? false, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(false); XYItemRenderer r = plot.getRenderer(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 6, 6)); renderer.setSeriesPaint(0, Color.BLUE); renderer.setSeriesShape(1, new Rectangle2D.Double(-3, -3, 6, 6)); renderer.setSeriesPaint(1, Color.RED); NumberAxis vaxis = (NumberAxis) plot.getRangeAxis(); vaxis.setAutoRange(true); vaxis.setAxisLineVisible(true); vaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); vaxis.setTickMarksVisible(true); DateAxis daxis = (DateAxis) plot.getDomainAxis(); daxis.setRange(fromDate, toDate); if (intervalUnitClass == Month.class) { DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(); dateFormatSymbols .setShortMonths(new String[] { "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D" }); daxis.setDateFormatOverride(new SimpleDateFormat("MMM", dateFormatSymbols)); } return chart; }
From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java
/** * Creates a random dataset./* w ww .j ava2s. 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.o4s.sarGrapher.graph.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w ww .j a v a2 s .co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { TimeSeriesCollection dataset = new TimeSeriesCollection(); String title = ""; String ytitle = ""; int width = 400; int height = 300; String graphType = "LINE"; Boolean useSSH = false; HttpSession session = request.getSession(); if (session != null && session.getAttribute("jsch") != null) { useSSH = true; } for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String name = e.nextElement().toString(); String val = request.getParameter(name); if (val == null) continue; // seems unnecessary but for code clarity else if (name.equals("title")) title = val; else if (name.equals("ytitle")) ytitle = val; else if (name.equals("width")) width = Integer.parseInt(val); else if (name.equals("height")) height = Integer.parseInt(val); else if (name.equals("useSSH")) useSSH = true; else if (name.equals("type")) graphType = val; else { String[] fflds = val.split(":"); String fn = fflds[0]; String[] flds = fflds[1].split(","); if (fn == null) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, "Unable to find filename from: {0}={1}", new Object[] { name, val }); return; } CSV c = null; if (useSSH) { CSVs cs = new CSVs(); c = cs.get(fn); } if (c == null) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, "Unable to find CSV: {0}", fn); return; } ArrayList ds = new ArrayList(); for (int i = 0; i < flds.length; i++) ds.add(new TimeSeries(name + "." + flds[i])); try { c.open(); do { try { if (!c.next()) break; } catch (Exception ex) { // Missing field if (ex.getMessage().startsWith("Missing fields")) break; Logger.getLogger(graph.class.getName()).log(Level.SEVERE, null, ex); } String heure = (String) c.get("heure"); for (int i = 0; i < flds.length; i++) { Double fv; val = (String) c.get(flds[i]); if (val != null) { fv = Double.parseDouble(val); } else { // try to replace variable String str = flds[i]; for (String s : c.getFields()) { str = str.replaceAll(s, c.get(s).toString()); } Expression exp = new ExpressionBuilder(str).build(); ValidationResult v = exp.validate(); String errorMsg = ""; if (!v.isValid()) { for (String s : v.getErrors()) { errorMsg += (errorMsg.isEmpty() ? "" : ",") + s; } if (!errorMsg.isEmpty()) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, "Syntax ERROR or missing variables: {0}", errorMsg); } } fv = exp.evaluate(); } //dataset.addValue(fv,flds[i],heure); Date dt = new SimpleDateFormat("HH:mm:ss").parse(heure); ((TimeSeries) ds.get(i)).addOrUpdate(new Minute(dt), fv); } } while (true); } catch (Exception ex) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, null, ex); } for (int i = 0; i < flds.length; i++) dataset.addSeries((TimeSeries) ds.get(i)); } } //JFreeChart barChart = ChartFactory.createBarChart(title, "", "Unit vendue", dataset, PlotOrientation.VERTICAL, true, true, false); //JFreeChart barChart = ChartFactory.createTimeSeriesChart(title, title, dataDir, dataset);// .createStackedBarChart(title, "", "", dataset); // JFreeChart timechart = ChartFactory.createTimeSeriesChart( // title, // Title // "Heure", // X-axis Label // "", // Y-axis Label // dataset, // Dataset // true, // Show legend // true, // Use tooltips // false // Generate URLs // ); // Plot p=timechart.getPlot(); XYItemRenderer r; if (graphType.equals("AREA")) { r = new XYAreaRenderer(); } else if (graphType.equals("BAR")) { r = new XYBarRenderer(); } else if (graphType.equals("STACK")) { r = new StackedXYAreaRenderer(); } else { r = new StandardXYItemRenderer(); } final DateAxis domainAxis = new DateAxis("Heure"); domainAxis.setVerticalTickLabels(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); final ValueAxis rangeAxis = new NumberAxis(ytitle); final XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, r); final JFreeChart chart = new JFreeChart(title, plot); // JFreeChart timechart=null; // if( graphType.equals("AREA") ){ // timechart = ChartFactory.createXYAreaChart(title, "Heure", "", dataset, PlotOrientation.VERTICAL, true, true, false); // } else if( graphType.equals("BAR") ){ // timechart = ChartFactory.createXYBarChart(title, "Heure", true, "", dataset, PlotOrientation.VERTICAL, true, true, false); // } else { // timechart = ChartFactory.createXYLineChart(title, "Heure", "", dataset, PlotOrientation.VERTICAL, true, true, false); // } response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, width, height); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Some checks for the {@link TimeSeriesCollection#removeSeries(int)} * method.// w ww.jav a 2 s . c om */ @Test public void testRemoveSeries_int() { TimeSeriesCollection c1 = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("Series 1"); TimeSeries s2 = new TimeSeries("Series 2"); TimeSeries s3 = new TimeSeries("Series 3"); TimeSeries s4 = new TimeSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(2); assertTrue(c1.getSeries(2).equals(s4)); c1.removeSeries(0); assertTrue(c1.getSeries(0).equals(s2)); assertEquals(2, c1.getSeriesCount()); }
From source file:org.jfree.expdemo.SelectionDemo1.java
/** * Creates a dataset, consisting of two series of monthly data. * //from ww w . ja v a 2 s .co m * @return The dataset. */ private static TimeSeriesCollection createDataset() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Month(1, 2009), 181.8); s1.add(new Month(2, 2009), 167.3); s1.add(new Month(3, 2009), 153.8); s1.add(new Month(4, 2009), 167.6); s1.add(new Month(5, 2009), 158.8); s1.add(new Month(6, 2009), 148.3); s1.add(new Month(7, 2009), 153.9); s1.add(new Month(8, 2009), 142.7); s1.add(new Month(9, 2009), 123.2); s1.add(new Month(10, 2009), 131.8); s1.add(new Month(11, 2009), 139.6); s1.add(new Month(12, 2009), 142.9); s1.add(new Month(1, 2010), 138.7); s1.add(new Month(2, 2010), 137.3); s1.add(new Month(3, 2010), 143.9); s1.add(new Month(4, 2010), 139.8); s1.add(new Month(5, 2010), 137.0); s1.add(new Month(6, 2010), 132.8); TimeSeries s2 = new TimeSeries("S2"); s2.add(new Month(1, 2009), 129.6); s2.add(new Month(2, 2009), 123.2); s2.add(new Month(3, 2009), 117.2); s2.add(new Month(4, 2009), 124.1); s2.add(new Month(5, 2009), 122.6); s2.add(new Month(6, 2009), 119.2); s2.add(new Month(7, 2009), 116.5); s2.add(new Month(8, 2009), 112.7); s2.add(new Month(9, 2009), 101.5); s2.add(new Month(10, 2009), 106.1); s2.add(new Month(11, 2009), 110.3); s2.add(new Month(12, 2009), 111.7); s2.add(new Month(1, 2010), 111.0); s2.add(new Month(2, 2010), 109.6); s2.add(new Month(3, 2010), 113.2); s2.add(new Month(4, 2010), 111.6); s2.add(new Month(5, 2010), 108.8); s2.add(new Month(6, 2010), 101.6); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java
/** * Creates a sample dataset.// ww w.j a v a2s . 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 static XYDataset createDataset(String name, double base, RegularTimePeriod start, int count) { TimeSeries series = new TimeSeries(name); 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); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); return dataset; }
From source file:grafici.PazientiTimeSeriesChart.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset./*from w w w . ja v a 2 s . c om*/ */ private static XYDataset createDataset(int tipo) { TimeSeries s1 = new TimeSeries(titolo); s1.add(new Month(2, 2001), 181.8); TimeSeries s2 = new TimeSeries("aaa"); s2.add(new Month(2, 2001), 129.6); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }