List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, Class timePeriodClass)
From source file:net.sf.profiler4j.console.MemoryPlotPanel.java
public MemoryPlotPanel(int maxAge, String title) { super(new BorderLayout()); totalSeries = new TimeSeries("Committed Memory", Millisecond.class); totalSeries.setMaximumItemAge(maxAge); usedSeries = new TimeSeries("Used Memory", Millisecond.class); usedSeries.setMaximumItemAge(maxAge); TimeSeriesCollection seriesCollection = new TimeSeriesCollection(); seriesCollection.addSeries(totalSeries); seriesCollection.addSeries(usedSeries); NumberAxis numberAxis = new NumberAxis("Memory (KB)"); numberAxis.setLabelFont(new Font("SansSerif", 0, 14)); numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); DateAxis dateAxis = new DateAxis("Time"); dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateAxis.setLabelFont(new Font("SansSerif", 0, 14)); dateAxis.setAutoRange(true);/* w w w. ja va 2 s . c om*/ dateAxis.setLowerMargin(0); dateAxis.setUpperMargin(0); dateAxis.setTickLabelsVisible(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesPaint(1, Color.GREEN.darker()); lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true); chart.setBackgroundPaint(Color.white); ChartPanel panel = new ChartPanel(chart); panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY))); add(panel); setBorder(createEmptyBorder(8, 8, 8, 8)); }
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//from w w w .ja v a 2s . c om */ 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:studio.ui.LineChart.java
public static JFreeChart createDataset(KTableModel table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;/* w w w . j ava 2 s . c o m*/ 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.codehaus.mojo.chronos.chart.SummaryGCChartSource.java
public JFreeChart getChart(ResourceBundle bundle, ReportConfig config) { String beforeLabel = bundle.getString("chronos.label.gc.before"); String afterLabel = bundle.getString("chronos.label.gc.after"); TimeSeriesCollection dataset1 = new TimeSeriesCollection(); TimeSeries heapBeforeSeries = new TimeSeries(beforeLabel, Millisecond.class); samples.extractHeapBefore(heapBeforeSeries); TimeSeries heapAfterSeries = new TimeSeries(afterLabel, Millisecond.class); samples.extractHeapAfter(heapAfterSeries); dataset1.addSeries(heapBeforeSeries); dataset1.addSeries(heapAfterSeries); TimeSeriesCollection dataset = dataset1; String title = bundle.getString("chronos.label.gc"); String timeLabel = bundle.getString("chronos.label.gc.time"); String valueLabel = bundle.getString("chronos.label.gc.mem"); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, timeLabel, valueLabel, dataset, true, true, false);/*from ww w. j a va 2 s . com*/ ChartUtil.setupXYPlot(chart, new SimpleDateFormat("HH:mm:ss")); return chart; }
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static JFreeChart createTimeSeriesChart(String title, List<TimeSeriesChartSpecification> specifications, String xLabel, String yLabel, ColorTheme theme) { TimeSeriesCollection dataCollection = new TimeSeriesCollection(); for (TimeSeriesChartSpecification specification : specifications) { TimeSeries series = new TimeSeries(specification.getLabel(), Millisecond.class); for (Map.Entry<Date, Double> point : specification.getData().entrySet()) { series.add(new Millisecond(point.getKey()), point.getValue()); }/*from w w w . ja v a2 s. c o m*/ dataCollection.addSeries(series); } JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataCollection, true, false, false); formatColorTheme(chart, theme); XYPlot plot = chart.getXYPlot(); Color[] colors = generateJetSpectrum(specifications.size()); for (int i = 0; i < specifications.size(); i++) { plot.getRenderer().setSeriesPaint(i, colors[i]); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm:ss")); return chart; }
From source file:com.geminimobile.chart.GeminiChartUtil.java
public void createReport(OutputStream out, List<ChartSeries> chartData, String strTitle, String strDomainAxisLabel) { strDomainAxisLabel = "Time Interval: " + strDomainAxisLabel; String strYAxisLabel;/*from w ww . j av a2 s.c o m*/ //String strCategoryType = " "; strYAxisLabel = "Count"; //SimpleDateFormat sdf = new SimpleDateFormat("MMMM-dd hh:mm a"); //build a dataset as needed by JFreeChart // note: strCategoryType is for a chart with multiple categories. // i.e. idisplay multiple bars for each time interval. // TimeSeriesCollection dataSet = new TimeSeriesCollection(); // For each series of data, create a TimeSeries for (int i = 0; i < chartData.size(); i++) { ChartSeries chartSeries = chartData.get(i); TimeSeries timeSeries = new TimeSeries(chartSeries.getName(), Millisecond.class); List<ChartValueByTime> data = chartSeries.getData(); //int cumulValue = 0; for (int j = 0; j < data.size(); j++) { ChartValueByTime chartVal = data.get(j); Millisecond ms = new Millisecond(new Date(chartVal.getTime())); // *NOT* Store the cumulative value . So maintain a running total. //cumulValue += chartVal.getValue(); //timeSeries.add(ms, cumulValue); timeSeries.add(ms, chartVal.getValue()); } dataSet.addSeries(timeSeries); } JFreeChart lineChart = ChartFactory.createTimeSeriesChart(strTitle, // chart title strDomainAxisLabel, // domain axis label strYAxisLabel, // range axis label dataSet, // data true, // legend false, // tooltips false // urls ); try { ChartUtilities.writeChartAsPNG(out, lineChart, 800, 400); } catch (IOException e) { e.printStackTrace(); } }
From source file:grafix.graficos.eixos.EixoVolume.java
private IntervalXYDataset criarVolumeDataset(JanelaGraficos janela) { TimeSeries serie = new TimeSeries(janela.getAcao().getCodAcao() + " (volume)", Day.class); IntervaloExibicao intervalo = janela.getIntervaloExibicao(); for (int i = intervalo.getInicio(); i < intervalo.getFim(); i++) { RegistroDiario reg = janela.getAcao().getRegistro(i); serie.add(reg.getData(Controle.getConfiguracoesUsuario().isExibeSomenteDiasUteis()), reg.getVolumeDinheiro() / 1000); }//w w w . j a v a2 s. c om return new TimeSeriesCollection(serie); }
From source file:ws.moor.bt.grapher.ChartBuilder.java
private TimeSeries constructSeries(String name, CSVStream stream) { TimeSeries series = new TimeSeries(name, FixedMillisecond.class); while (stream.hasMoreEntries()) { CSVEntry entry = stream.nextEntry(); series.addOrUpdate(new FixedMillisecond(entry.getDate()), entry.getValue()); }// w w w . ja va2 s . com return series; }
From source file:org.jfree.chart.demo.TimeSeriesDemo10.java
/** * A demonstration application./*from w ww . j a va 2 s .c o m*/ * * @param title the frame title. */ public TimeSeriesDemo10(final String title) { super(title); final TimeSeries series = new TimeSeries("Per Minute Data", Minute.class); final Hour hour = new Hour(); series.add(new Minute(1, hour), 10.2); series.add(new Minute(3, hour), 17.3); series.add(new Minute(9, hour), 14.6); series.add(new Minute(11, hour), 11.9); series.add(new Minute(15, hour), 13.5); series.add(new Minute(19, hour), 10.9); final TimeSeriesCollection dataset = new TimeSeriesCollection(series); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 10", "Time", "Value", dataset, true, true, false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:netplot.TimeSeriesPlotPanel.java
@SuppressWarnings("deprecation") public void addPlot() { int plotIndex = timeSeriesList.size(); TimeSeries timeSeries = new TimeSeries(plotName, Millisecond.class); timeSeriesList.add(timeSeries);// w ww . ja va 2 s . c o m TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(timeSeries); ((XYPlot) chart.getPlot()).setDataset(plotIndex, dataset); genericConfig(chart, (XYPlot) chart.getPlot(), plotIndex); }