List of usage examples for org.jfree.data.time TimeSeriesCollection TimeSeriesCollection
public TimeSeriesCollection()
From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java
/** * The constructor./*w w w . jav a 2 s . c o m*/ */ public LiveDataMonitor() { _attListener = new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { // aah, is this for the scenario we're watching if (_myIndexedAttr != null) if (evt.getSource() == _myIndexedAttr.index) { final DataDoublet newD = (DataDoublet) evt.getNewValue(); final long time = newD.getTime(); final Object newValue = newD.getValue(); if (newValue instanceof Number) { final Number value = (Number) newValue; // and store it final TimeSeriesCollection coll = (TimeSeriesCollection) _chart.getXYPlot() .getDataset(); TimeSeries tmpSeries; if (coll == null) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); tmpSeries = new TimeSeries(_watchedAttr.getName()); dataset.addSeries(tmpSeries); // add to series in different thread... Display.getDefault().asyncExec(new Runnable() { public void run() { _chart.getXYPlot().setDataset(dataset); } }); } else { tmpSeries = coll.getSeries(0); } final TimeSeries series = tmpSeries; // add to series in current thread, accepting it will slow down // the // UI Display.getDefault().syncExec(new Runnable() { public void run() { // are we still open?i if (!_chartFrame.isDisposed()) { // sure, go for it, series.addOrUpdate(new Millisecond(new Date(time)), value); } } }); } } } }; }
From source file:org.cerberus.crud.service.impl.TestCaseExecutionwwwDetService.java
@Override public BufferedImage getHistoricOfParameter(TestCase testcase, String parameter) { List<TestCaseExecutionwwwSumHistoric> historic = testCaseExecutionWWWDetDAO .getHistoricForParameter(testcase, parameter); BufferedImage result = null;/*from w w w. j a va 2s . c om*/ DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); /*Create timeseries with the data*/ String timeseriesname = parameter; TimeSeries timeseries = new TimeSeries(timeseriesname, Minute.class); for (TestCaseExecutionwwwSumHistoric ep : historic) { defaultcategorydataset.addValue(Float.valueOf(ep.getParameter()), parameter, ep.getStart()); if (!ep.getStart().equals("2011-01-01 00:00")) { String tims = ep.getStart(); int year = Integer.valueOf(tims.substring(0, 4)); int month = Integer.valueOf(tims.substring(5, 7)); int day = Integer.valueOf(tims.substring(8, 10)); int hour = Integer.valueOf(tims.substring(11, 13)); int min = Integer.valueOf(tims.substring(14, 16)); float value = Float.valueOf(ep.getParameter()); timeseries.addOrUpdate(new Minute(min, hour, day, month, year), value); } } timeseriescollection.addSeries(timeseries); result = this.bi(timeseriescollection, "test", parameter, 1); return result; }
From source file:view.PrograssCharts.java
/** * Creates new form PrograssCharts//from www . j a v a 2 s .c o m */ public PrograssCharts(java.awt.Frame parent, boolean modal) { super(parent, modal); try { initComponents(); setSize(1400, 800); jPanel1.setVisible(false); jPanel2.setVisible(false); new Thread(new Runnable() { @Override public void run() { loading1(); loading2(); run(); } }).start(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset.setValue(QuestionLab.cat1, "gfdg", "Collectns"); dataset.setValue(QuestionLab.cat2, "gfdg", "Data"); dataset.setValue(QuestionLab.cat3, "gfdg", "Dev"); dataset.setValue(QuestionLab.cat4, "gfdg", "Excep"); dataset.setValue(QuestionLab.cat5, "gfdg", "File"); dataset.setValue(QuestionLab.cat6, "gfdg", "FlowCon"); dataset.setValue(QuestionLab.cat7, "gfdg", "Format"); dataset.setValue(QuestionLab.cat8, "gfdg", "GC"); dataset.setValue(QuestionLab.cat9, "gfdg", "IC"); dataset.setValue(QuestionLab.cat10, "gfdg", "VarArgs"); dataset.setValue(QuestionLab.cat11, "gfdg", "Fundamt"); dataset.setValue(QuestionLab.cat12, "gfdg", "Modif"); dataset.setValue(QuestionLab.cat13, "gfdg", "OOP"); dataset.setValue(QuestionLab.cat14, "gfdg", "Vari"); dataset.setValue(QuestionLab.cat15, "gfdg", "String"); dataset.setValue(QuestionLab.cat16, "gfdg", "Threads"); dataset.setValue(QuestionLab.cat17, "gfdg", "WC"); JFreeChart freeChart = ChartFactory.createBarChart("Exam Prograss by Subjects", "Subject", "Marks", dataset, PlotOrientation.VERTICAL, false, true, false); //JFreeChart freeChart1 = ChartFactory.createBarChart("Income", " Name", "Incomesss", dataset1, PlotOrientation.VERTICAL, false, true, false); TimeSeries pop = new TimeSeries("Population", Day.class); //JFreeChart chart=ChartFactory.create CategoryPlot plot = freeChart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Exam Prograss", freeChart); // frame.setVisible(true); // frame.setSize(550, 450); // JPanel jPanel1 = new JPanel(); jPanel1.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(freeChart); CP.setPreferredSize(new Dimension(785, 440)); CP.setMouseWheelEnabled(true); jPanel1.add(CP); jPanel1.revalidate(); ArrayList<Exam> setChartValue = ServerConnector.getServerConnector().getExamController() .getPreviousMarks(PracticeExamLogIn.studentNic); for (Exam exam : setChartValue) { //dataset1.setValue(exam.getMarks(), "gfdg9", exam.getDate()); pop.addOrUpdate(new Day(exam.getDate()), exam.getMarks()); System.out.println("mar" + exam.getMarks()); System.out.println("date" + exam.getDate()); } TimeSeriesCollection myDataset = new TimeSeriesCollection(); myDataset.addSeries(pop); JFreeChart myChart = ChartFactory.createTimeSeriesChart("Population Your Marks", "Date", "Population", myDataset, true, true, false); //try { //ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 500, 300); //} catch (IOException e) { //System.err.println("Problem occurred creating chart."); //} //JFreeChart chart=ChartFactory.create CategoryPlot plot1 = freeChart.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.BLUE); //ChartFrame frame1 = new ChartFrame("Exam Prograss", freeChart1); // frame.setVisible(true); // frame.setSize(550, 450); // JPanel jPanel1 = new JPanel(); jPanel2.setLayout(new java.awt.BorderLayout()); ChartPanel CP1 = new ChartPanel(myChart); CP1.setPreferredSize(new Dimension(785, 440)); CP1.setMouseWheelEnabled(true); jPanel2.add(CP1); jPanel2.revalidate(); } catch (RemoteException | ClassNotFoundException | SQLException | NotBoundException | MalformedURLException ex) { Logger.getLogger(PrograssCharts.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.charts.ThreeMonthChart.java
public ThreeMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);//from w w w. j ava 2s. c om rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.SixMonthChart.java
public SixMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);//from w w w . jav a 2 s.com rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.OneMonthChart.java
public OneMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);// w w w.j av a 2 s . c o m rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setVerticalTickLabels(true); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-dd")); xAxis.setAutoTickUnitSelection(false); xAxis.setAutoRange(false); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
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. c o m 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:pt.lsts.neptus.util.bathymetry.TidCachedData.java
public static void test(String[] args) throws Exception { TidReader.main(args);/*w ww. ja v a2 s. c om*/ JFreeChart timeSeriesChart = null; TimeSeriesCollection tsc = new TimeSeriesCollection(); ValueMarker marker = new ValueMarker(System.currentTimeMillis()); ValueMarker levelMarker = new ValueMarker(0); String tmpFolder = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator", "/"); File tidFx = new File(tmpFolder + "tmp.tid"); TidCachedData tide = new TidCachedData(tidFx); TimeSeries ts = new TimeSeries(I18n.text("Tide level")); tsc.addSeries(ts); Date sDate = new GregorianCalendar(1993, 9, 28).getTime(); for (double i = -12; i < 12; i += 0.25) { Date d = new Date((long) (sDate.getTime() + (i * 6.45 * 1E3 * 60 * 60))); ts.addOrUpdate(new Millisecond(d), tide.getTidePrediction(d, false)); } JPanel panel = new JPanel(new BorderLayout()); timeSeriesChart = ChartFactory.createTimeSeriesChart(null, null, null, tsc, true, true, true); panel.add(new ChartPanel(timeSeriesChart), BorderLayout.CENTER); timeSeriesChart.getXYPlot().addDomainMarker(marker); levelMarker.setValue(TidePredictionFactory.getTideLevel(new Date())); timeSeriesChart.getXYPlot().addRangeMarker(levelMarker); GuiUtils.testFrame(panel); System.out.println("\n________________________________________"); long start = System.currentTimeMillis(); TidCachedData tcd = new TidCachedData(new File(ConfigFetch.getConfFolder() + "mra/Leixoes.tid")); System.out.println("Loading of " + tcd.getName() + " took " + MathMiscUtils.parseToEngineeringNotation((System.currentTimeMillis() - start) / 1E3, 2) + "s"); }
From source file:compecon.dashboard.panel.MoneyPanel.java
protected ChartPanel createMoneyCirculationPanel() { TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); for (Currency currency : Currency.values()) timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).moneyCirculationModel.getTimeSeries()); JFreeChart chart = ChartFactory.createTimeSeriesChart("Money Circulation", "Date", "Money Circulation", timeSeriesCollection, true, true, false); configureChart(chart);//from w ww. j a v a 2 s . co m return new ChartPanel(chart); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Some checks for the {@link TimeSeriesCollection#removeSeries(int)} * method./* ww w . ja v a 2 s . c o m*/ */ @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()); }