List of usage examples for org.jfree.data.time TimeSeriesCollection TimeSeriesCollection
public TimeSeriesCollection(TimeSeries series)
From source file:studio.ui.LineChart.java
public static JFreeChart createDataset(KTableModel table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;//from w w w .j ava 2 s .c om if (table.getColumnCount() > 0) { Class klass = table.getColumnClass(0); if ((klass == K.KTimestampVector.class) || (klass == K.KTimespanVector.class) || (klass == K.KDateVector.class) || (klass == K.KTimeVector.class) || (klass == K.KMonthVector.class) || (klass == K.KMinuteVector.class) || (klass == K.KSecondVector.class) || (klass == K.KDatetimeVector.class)) { TimeSeriesCollection tsc = new TimeSeriesCollection(tz); for (int col = 1; col < table.getColumnCount(); col++) { TimeSeries series = null; try { if (klass == K.KDateVector.class) { series = new TimeSeries(table.getColumnName(col), Day.class); K.KDateVector dates = (K.KDateVector) table.getColumn(0); for (int row = 0; row < dates.getLength(); row++) { K.KDate date = (K.KDate) dates.at(row); Day day = new Day(date.toDate(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(day, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimeVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KTimeVector times = (K.KTimeVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KTime time = (K.KTime) times.at(row); Millisecond ms = new Millisecond(time.toTime(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimestampVector.class) { series = new TimeSeries(table.getColumnName(col), Day.class); K.KTimestampVector dates = (K.KTimestampVector) table.getColumn(0); for (int row = 0; row < dates.getLength(); row++) { K.KTimestamp date = (K.KTimestamp) dates.at(row); Day day = new Day(new java.util.Date(date.toTimestamp().getTime()), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(day, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimespanVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KTimespanVector times = (K.KTimespanVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KTimespan time = (K.KTimespan) times.at(row); Millisecond ms = new Millisecond(time.toTime(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KDatetimeVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KDatetimeVector times = (K.KDatetimeVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KDatetime time = (K.KDatetime) times.at(row); Millisecond ms = new Millisecond(time.toTimestamp(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KMonthVector.class) { series = new TimeSeries(table.getColumnName(col), Month.class); K.KMonthVector times = (K.KMonthVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Month time = (K.Month) times.at(row); int m = time.i + 24000; int y = m / 12; m = 1 + m % 12; Month month = new Month(m, y); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(month, ((ToDouble) o).toDouble()); } } else if (klass == K.KSecondVector.class) { series = new TimeSeries(table.getColumnName(col), Second.class); K.KSecondVector times = (K.KSecondVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Second time = (K.Second) times.at(row); Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(second, ((ToDouble) o).toDouble()); } } else if (klass == K.KMinuteVector.class) { series = new TimeSeries(table.getColumnName(col), Minute.class); K.KMinuteVector times = (K.KMinuteVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Minute time = (K.Minute) times.at(row); Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(minute, ((ToDouble) o).toDouble()); } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) tsc.addSeries(series); } ds = tsc; } else if ((klass == K.KDoubleVector.class) || (klass == K.KFloatVector.class) || (klass == K.KShortVector.class) || (klass == K.KIntVector.class) || (klass == K.KLongVector.class)) { XYSeriesCollection xysc = new XYSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { XYSeries series = null; try { series = new XYSeries(table.getColumnName(col)); for (int row = 0; row < table.getRowCount(); row++) { double x = ((ToDouble) table.getValueAt(row, 0)).toDouble(); double y = ((ToDouble) table.getValueAt(row, col)).toDouble(); series.add(x, y); } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) xysc.addSeries(series); } ds = xysc; } } if (ds != null) { boolean legend = false; if (ds.getSeriesCount() > 1) legend = true; if (ds instanceof XYSeriesCollection) return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true); else if (ds instanceof TimeSeriesCollection) return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true); } return null; }
From source file:org.gaixie.micrite.car.action.CarfileChartAction.java
/** * ?//w ww .j ava2s . c o m * @return */ private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("??", org.jfree.data.time.Minute.class); Hour hour = new Hour(); timeseries.add(new Minute(1, hour), 10.199999999999999D); timeseries.add(new Minute(3, hour), 17.300000000000001D); timeseries.add(new Minute(9, hour), 14.6D); timeseries.add(new Minute(11, hour), 11.9D); timeseries.add(new Minute(15, hour), 13.5D); timeseries.add(new Minute(19, hour), 10.9D); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries); return timeseriescollection; }
From source file:org.gaixie.micrite.crm.action.CustomerChartAction.java
/** * ?/* ww w . ja va 2 s . c o m*/ * @return */ private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("Per Minute Data", org.jfree.data.time.Minute.class); Hour hour = new Hour(); timeseries.add(new Minute(1, hour), 10.199999999999999D); timeseries.add(new Minute(3, hour), 17.300000000000001D); timeseries.add(new Minute(9, hour), 14.6D); timeseries.add(new Minute(11, hour), 11.9D); timeseries.add(new Minute(15, hour), 13.5D); timeseries.add(new Minute(19, hour), 10.9D); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries); return timeseriescollection; }
From source file:temp1.RealTimeChart.java
public static JFreeChart createChart(String chartContent, String title, String yaxisName) { thread1 = new Thread(); timeseries1 = new TimeSeries(chartContent, Millisecond.class); timeseries2 = new TimeSeries(chartContent, Millisecond.class); timeseries3 = new TimeSeries(chartContent, Millisecond.class); timeseries4 = new TimeSeries(chartContent, Millisecond.class); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1); TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2); TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3); TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4); jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false); final XYPlot xyplot = jfreechart.getXYPlot(); xyplot.setOutlinePaint(Color.magenta); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.gray); xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true);/* ww w .j a v a2s.com*/ valueaxis.setFixedAutoRange(20000D); //Value valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(800D, 3300D); xyplot.setDataset(0, timeseriescollection); xyplot.setDataset(1, timeseriescollection1); xyplot.setDataset(2, timeseriescollection2); xyplot.setDataset(3, timeseriescollection3); XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer(); xylineandshaperenderer0.setBaseShapesVisible(false); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer3.setBaseShapesVisible(false); xylineandshaperenderer0.setSeriesPaint(0, Color.RED); xylineandshaperenderer1.setSeriesPaint(0, Color.cyan); xylineandshaperenderer2.setSeriesPaint(0, Color.yellow); xylineandshaperenderer3.setSeriesPaint(0, Color.blue); xyplot.setRenderer(0, xylineandshaperenderer0); xyplot.setRenderer(1, xylineandshaperenderer1); xyplot.setRenderer(2, xylineandshaperenderer2); xyplot.setRenderer(3, xylineandshaperenderer3); //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F)); return jfreechart; }
From source file:com.testmax.framework.CreateGraph.java
protected void createChart(double timeout) { TimeSeriesCollection dataset = new TimeSeriesCollection(ts); this.chart = ChartFactory.createTimeSeriesChart(this.graphName, this.xName, this.yName, dataset, true, true, false);/*from w ww. ja v a2s. c o m*/ final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(timeout * 1000.0); JFrame frame = new JFrame(this.graphName); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ChartPanel label = new ChartPanel(chart); frame.getContentPane().add(label); //Suppose I add combo boxes and buttons here later frame.pack(); if (ConfigLoader.getConfig("SHOW_GRAPH_RUNTIME").equalsIgnoreCase("yes")) { frame.setVisible(true); } else { frame.setVisible(false); } }
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 w ww . j a v a2s. c om 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:uk.co.bssd.reporting.chart.TimeSeriesChart.java
private XYDataset convertDataset(String seriesName, TimedDatapoints<T> timedDatapoints) { TimeSeries series = new TimeSeries(seriesName); for (TimedDatapoint<T> timedDatapoint : timedDatapoints) { Millisecond regularTimePeriod = new Millisecond(timedDatapoint.timestamp().toDate()); series.add(regularTimePeriod, timedDatapoint.value()); }//from w w w .j av a 2 s . c o m return new TimeSeriesCollection(series); }
From source file:de.stefanwndelmann.zy1270logger.ZY1270LoggerMain.java
private void initJFreeChart() { voltageSeries = new TimeSeries("Voltage"); ampSeries = new TimeSeries("Amps"); wattSeries = new TimeSeries("Watt"); dataset = new TimeSeriesCollection(voltageSeries); dataset.addSeries(ampSeries);//from www . j a v a 2 s. c om dataset.addSeries(wattSeries); chart = ChartFactory.createTimeSeriesChart("Live Data", "Time", "U/I/P", dataset); DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss.SSS")); chart.setAntiAlias(true); chart.setTextAntiAlias(true); chartPanel = new ChartPanel(chart); jFreeChartPanel.add(chartPanel, BorderLayout.CENTER); }
From source file:org.activequant.util.charting.EquityChart.java
/** * sets the equity chart on this object, but does not render it. Call renderToXYZ to actually render it. * @param balanceBook//ww w.j av a 2s . co m */ public void createEquityChart(BalanceBook balanceBook) { final TimeSeries ts = new TimeSeries("Equity curve", Millisecond.class); double value = 0.0; for (BalanceEntry be : balanceBook.getBalanceEntries()) { value += be.getValue(); ts.addOrUpdate(new Millisecond(be.getTimeStamp().getDate()), value); } final TimeSeriesCollection dataset = new TimeSeriesCollection(ts); final XYPlot plot1 = chart.getXYPlot(); plot1.setDataset(0, dataset); }
From source file:org.jfree.chart.demo.TimeSeriesDemo7.java
/** * A demonstration application showing how to create a simple time series chart. * * @param title the frame title.//from w ww . j a v a 2 s. c o m */ public TimeSeriesDemo7(final String title) { super(title); // create a title... final String chartTitle = "Time Series Demo"; final XYDataset dataset = new TimeSeriesCollection(DemoDatasetFactory.createEURTimeSeries()); final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Value", dataset, true, true, false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }