List of usage examples for org.jfree.data.time TimeSeriesCollection addSeries
public void addSeries(TimeSeries series)
From source file:org.yccheok.jstock.gui.charting.DynamicChart.java
/** Creates new form DynamicChart */ public DynamicChart() { this.price = new TimeSeries("Price"); // Sets the maximumItemAge attribute, which specifies the maximum age of data items in the series // (in terms of the RegularTimePeriod type used by this series). Whenever a new data value is // added, any data items that are older than the limit specified by maximumItemAge are automatically // discarded/*from ww w .j a v a 2 s . c o m*/ // Maximum 2 hours. this.price.setMaximumItemAge(2 * 60 * 60); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.price); JFreeChart freeChart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, true, false); freeChart.setAntiAlias(true); while (freeChart.getSubtitleCount() > 0) { freeChart.removeSubtitle(freeChart.getSubtitle(0)); } // Due to limited spacing, we remove all information regarding x and y axis // as well. XYPlot plot = freeChart.getXYPlot(); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#"))); org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart); // Disable zoom. chartPanel = new ChartPanel(freeChart, true, true, true, false, true); chartPanel.setMouseZoomable(false); }
From source file:org.sonar.server.charts.jruby.TrendsChart.java
public void initSerie(Long serieId, String legend, boolean isPercent) { TimeSeries series = new TimeSeries(legend); int index = seriesById.size(); seriesById.put(serieId, series);/*from w ww . j a v a 2s . co m*/ TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection(); timeSeriesColl.addSeries(series); plot.setDataset(index, timeSeriesColl); if (isPercent) { if (percentAxisId == -1) { NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'")); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(100.0); rangeAxis.setLowerBound(0.0); plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT); plot.setRangeAxis(index, rangeAxis); plot.mapDatasetToRangeAxis(index, index); percentAxisId = index; } else { plot.mapDatasetToRangeAxis(index, percentAxisId); } } else { NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeMinimumSize(2.0); plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT); plot.setRangeAxis(index, rangeAxis); plot.mapDatasetToRangeAxis(index, index); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesPaint(0, COLORS[index % COLORS.length]); plot.setRenderer(index, renderer); }
From source file:mediamatrix.gui.JVMMemoryProfilerPanel.java
public JVMMemoryProfilerPanel() { initComponents();/* w w w . j a v a 2 s.c o m*/ profiler = new JVMMemoryProfiler(frequency); profiler.addListener(new JVMMemoryProfilerListener() { @Override public void addScore(long t, long f) { total.add(new Millisecond(), t); free.add(new Millisecond(), f); } }); total = new TimeSeries("Total Memory"); total.setMaximumItemCount(historyCount); free = new TimeSeries("Free Memory"); free.setMaximumItemCount(historyCount); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(total); dataset.addSeries(free); final DateAxis domain = new DateAxis("Time"); final NumberAxis range = new NumberAxis("Memory"); domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final XYItemRenderer renderer = new DefaultXYItemRenderer(); renderer.setSeriesPaint(0, Color.red); renderer.setSeriesPaint(1, Color.green); renderer.setBaseStroke(new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); final XYPlot plot = new XYPlot(dataset, domain, range, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); domain.setAutoRange(true); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setTickLabelsVisible(true); final JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot, true); chart.setBackgroundPaint(Color.white); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12)); add(chartPanel, BorderLayout.CENTER); }
From source file:DualAxisDemo2.java
/** * Creates a sample dataset./* w ww.j av a 2 s .co m*/ * * @return The dataset. */ private XYDataset createDataset1() { final TimeSeries s1 = new TimeSeries("Random Data 1", Month.class); s1.add(new Month(2, 2001), 181.8); s1.add(new Month(3, 2001), 167.3); 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); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; }
From source file:DualAxisDemo2.java
/** * Creates a sample dataset./*from www. j a v a 2s . c om*/ * * @return The dataset. */ private XYDataset createDataset2() { final TimeSeries s2 = new TimeSeries("Random Data 2", Month.class); s2.add(new Month(2, 2001), 429.6); s2.add(new Month(3, 2001), 323.2); s2.add(new Month(4, 2001), 417.2); s2.add(new Month(5, 2001), 624.1); s2.add(new Month(6, 2001), 422.6); s2.add(new Month(7, 2001), 619.2); s2.add(new Month(8, 2001), 416.5); s2.add(new Month(9, 2001), 512.7); s2.add(new Month(10, 2001), 501.5); s2.add(new Month(11, 2001), 306.1); s2.add(new Month(12, 2001), 410.3); s2.add(new Month(1, 2002), 511.7); s2.add(new Month(2, 2002), 611.0); s2.add(new Month(3, 2002), 709.6); s2.add(new Month(4, 2002), 613.2); s2.add(new Month(5, 2002), 711.6); s2.add(new Month(6, 2002), 708.8); s2.add(new Month(7, 2002), 501.6); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s2); return dataset; }
From source file:org.jfree.chart.demo.TimeSeriesDemo9.java
/** * Creates a sample dataset.// w ww. j a v a 2 s .c o m * * @return The dataset. */ public XYDataset createDataset() { final TimeSeriesCollection dataset = new TimeSeriesCollection(); for (int i = 0; i < 4; i++) { dataset.addSeries(createTimeSeries(i, 10)); } return dataset; }
From source file:edu.indiana.htrc.visual.HTRCSeriesChartDrawer.java
@Override public File draw() { Set<String> key_set = input_map.keySet(); Iterator<String> iter = key_set.iterator(); TimeSeries accessSeries = new TimeSeries(dataset_label, Day.class); while (iter.hasNext()) { String dateStr = iter.next(); // yyyy-MM-dd int value = input_map.get(dateStr); Date date = null;/*from w w w . j av a 2s . co m*/ try { date = format.parse(dateStr); System.out.println(date); cal.setTime(date); accessSeries.add( new Day(cal.get(Calendar.DATE), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)), value); } catch (ParseException e) { e.printStackTrace(); } } TimeSeriesCollection series_dataset = new TimeSeriesCollection(); series_dataset.addSeries(accessSeries); JFreeChart series_chart = ChartFactory.createTimeSeriesChart(chart_name, x_axis_label, y_axis_label, series_dataset, true, true, false); File img = new File("../webapps/HTRC-UI-AuditAnalyzer/images/" + System.currentTimeMillis() + ".jpg"); try { ChartUtilities.saveChartAsJPEG(img, series_chart, 1400, 600); } catch (IOException e) { e.printStackTrace(); } return img; }
From source file:org.mwc.debrief.sensorfusion.views.MouseClickSolutionDemo.java
/** * @param title/*from w w w .j a v a2 s . c om*/ * the frame title. */ public MouseClickSolutionDemo(final String title) { super(title); final TimeSeries s1 = new TimeSeries("Series to click"); s1.add(new Month(2, 2001), 181.8); s1.add(new Month(3, 2001), 167.3); s1.add(new Month(4, 2001), 153.8); s1.add(new Month(5, 2001), 167.6); s1.add(new Month(6, 2001), 152.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); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); final JFreeChart chart = ChartFactory.createTimeSeriesChart("[Alt]-click to switch orientation", // title "Time axis", // x-axis label "Value axis", // y-axis label dataset, // data false, // create legend? false, // generate tooltips? false // generate URLs? ); //FIX IS HERE fixProblem(chart); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(final ChartMouseEvent arg0) { } public void chartMouseClicked(final ChartMouseEvent arg0) { System.out.println("clicked on:" + arg0.getEntity()); if (arg0.getTrigger().isAltDown()) { if (chart.getXYPlot().getOrientation() == PlotOrientation.HORIZONTAL) chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL); else chart.getXYPlot().setOrientation(PlotOrientation.HORIZONTAL); } } }); setContentPane(chartPanel); }
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;/*from ww w. j a v a 2 s .com*/ 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:com.okmich.twitanalysis.gui.ApplicationFrame.java
private void setChartPanel(JPanel jpanel) { this.negativeSeries = new TimeSeries("Negative", Millisecond.class); this.postiveSeries = new TimeSeries("Positive", Millisecond.class); this.neutralSeries = new TimeSeries("Neutral", Millisecond.class); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.negativeSeries); dataset.addSeries(this.postiveSeries); dataset.addSeries(this.neutralSeries); final JFreeChart chart = createChart(dataset); chart.getXYPlot().getRenderer(0).setSeriesPaint(0, Color.RED); chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(2.0f)); chart.getXYPlot().getRenderer(0).setSeriesPaint(1, Color.GREEN); chart.getXYPlot().getRenderer(0).setSeriesStroke(1, new BasicStroke(2.0f)); chart.getXYPlot().getRenderer(0).setSeriesPaint(2, Color.GRAY); chart.getXYPlot().getRenderer(0).setSeriesStroke(2, new BasicStroke(2.0f)); chart.getPlot().setBackgroundPaint(Color.BLACK); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel tweetCountPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); tweetCountLabel = new JLabel(); setTweetCountLabel();/* w w w . j av a 2 s. c o m*/ tweetCountPanel.add(tweetCountLabel); jpanel.setLayout(new BorderLayout(10, 10)); jpanel.add(chartPanel, BorderLayout.CENTER); jpanel.add(tweetCountPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(jpanel); }