List of usage examples for org.jfree.data.time TimeSeriesCollection TimeSeriesCollection
public TimeSeriesCollection(TimeSeries series)
From source file:org.geoserver.wms.ncwms.GetTimeSeriesResponse.java
@SuppressWarnings("rawtypes") private void writeChart(GetFeatureInfoRequest request, FeatureCollectionType results, OutputStream output, String mimeType) throws IOException { final TimeSeries series = new TimeSeries("time", Millisecond.class); String valueAxisLabel = "Value"; String title = "Time series"; final String timeaxisLabel = "Date / time"; final List collections = results.getFeature(); if (collections.size() > 0) { SimpleFeatureCollection fc = (SimpleFeatureCollection) collections.get(0); title += " of " + fc.getSchema().getName().getLocalPart(); valueAxisLabel = fc.getSchema().getDescription().toString(); try (SimpleFeatureIterator fi = fc.features()) { while (fi.hasNext()) { SimpleFeature f = fi.next(); Date date = (Date) f.getAttribute("date"); Double value = (Double) f.getAttribute("value"); series.add(new Millisecond(date), value); }//from w w w . ja va 2s. c o m } } XYDataset dataset = new TimeSeriesCollection(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, timeaxisLabel, valueAxisLabel, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new XYLineAndShapeRenderer()); if (mimeType.startsWith("image/png")) { ChartUtilities.writeChartAsPNG(output, chart, IMAGE_WIDTH, IMAGE_HEIGHT); } else if (mimeType.equals("image/jpg") || mimeType.equals("image/jpeg")) { ChartUtilities.writeChartAsJPEG(output, chart, IMAGE_WIDTH, IMAGE_HEIGHT); } }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Test the getSurroundingItems() method to ensure it is returning the * values we expect./*from w w w.ja va2 s . co m*/ */ @Test public void testGetSurroundingItems() { TimeSeries series = new TimeSeries("Series 1"); TimeSeriesCollection collection = new TimeSeriesCollection(series); collection.setXPosition(TimePeriodAnchor.MIDDLE); // for a series with no data, we expect {-1, -1}... int[] result = collection.getSurroundingItems(0, 1000L); assertTrue(result[0] == -1); assertTrue(result[1] == -1); // now test with a single value in the series... Day today = new Day(); long start1 = today.getFirstMillisecond(); long middle1 = today.getMiddleMillisecond(); long end1 = today.getLastMillisecond(); series.add(today, 99.9); result = collection.getSurroundingItems(0, start1); assertTrue(result[0] == -1); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, middle1); assertTrue(result[0] == 0); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, end1); assertTrue(result[0] == 0); assertTrue(result[1] == -1); // now add a second value to the series... Day tomorrow = (Day) today.next(); long start2 = tomorrow.getFirstMillisecond(); long middle2 = tomorrow.getMiddleMillisecond(); long end2 = tomorrow.getLastMillisecond(); series.add(tomorrow, 199.9); result = collection.getSurroundingItems(0, start2); assertTrue(result[0] == 0); assertTrue(result[1] == 1); result = collection.getSurroundingItems(0, middle2); assertTrue(result[0] == 1); assertTrue(result[1] == 1); result = collection.getSurroundingItems(0, end2); assertTrue(result[0] == 1); assertTrue(result[1] == -1); // now add a third value to the series... Day yesterday = (Day) today.previous(); long start3 = yesterday.getFirstMillisecond(); long middle3 = yesterday.getMiddleMillisecond(); long end3 = yesterday.getLastMillisecond(); series.add(yesterday, 1.23); result = collection.getSurroundingItems(0, start3); assertTrue(result[0] == -1); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, middle3); assertTrue(result[0] == 0); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, end3); assertTrue(result[0] == 0); assertTrue(result[1] == 1); }
From source file:Operacional.Janela2.java
private static IntervalXYDataset createDataset() { TimeSeries timeseries = new TimeSeries("Recebimento", "Year", "Count"); try {//from ww w .j a v a2 s . c o m timeseries.add(new Month(12, 1975), new Integer(1)); timeseries.add(new Month(11, 1975), new Integer(1)); timeseries.add(new Month(10, 1975), new Integer(1)); timeseries.add(new Month(9, 1975), new Integer(1)); } catch (Exception exception) { System.err.println(exception.getMessage()); } TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries); //timeseriescollection.setDomainIsPointsInTime(false); return timeseriescollection; }
From source file:org.ietr.preesm.mapper.ui.BestCostPlotter.java
/** * Creates a chart./*from w w w .j a v a 2 s .c o m*/ * * @return A chart. */ private JFreeChart createChart(String title) { final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[subplotCount]; for (int i = 0; i < subplotCount; i++) { this.lastValue[i] = 100.0; final TimeSeries series = new TimeSeries("Real Time", Millisecond.class); this.datasets[i] = new TimeSeriesCollection(series); final NumberAxis rangeAxis = new NumberAxis("Schedule"); rangeAxis.setAutoRangeIncludesZero(false); final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new XYLineAndShapeRenderer()); subplot.setBackgroundPaint(Color.white); subplot.setDomainGridlinePaint(Color.lightGray); subplot.setRangeGridlinePaint(Color.lightGray); plot.add(subplot); } final JFreeChart chart = new JFreeChart(title, plot); chart.removeLegend(); // chart.getLegend().setPosition(RectangleEdge.BOTTOM); chart.setBorderPaint(Color.lightGray); chart.setBorderVisible(true); Paint p = GanttPlotter.getBackgroundColorGradient(); chart.setBackgroundPaint(p); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.black); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); return chart; }
From source file:com.algodefu.yeti.data.Pass.java
private void calculateEquityChartImg() throws IOException { int i = 0;// w ww. j a va 2 s .c o m double sum = 0; TimeSeries equity = new TimeSeries("Equity"); // save values in temp array first, then use System.arraycopy to copy non empty values to this.equityArray double[][] tempEquityArr = new double[this.getTrades().length][4]; for (Trade trade : this.getTrades()) { if (trade.getCloseDateTime() != null) { sum += trade.getProfit(); equity.add(new Millisecond(Date.from(trade.getCloseDateTime().toInstant(ZoneOffset.UTC))), sum); tempEquityArr[i][0] = (double) trade.getCloseDateTime().toInstant(ZoneOffset.UTC).toEpochMilli(); tempEquityArr[i][1] = sum; tempEquityArr[i][2] = trade.getTradeID(); tempEquityArr[i][3] = trade.getProfit(); i++; } } this.equityArray = new double[i][4]; System.arraycopy(tempEquityArr, 0, this.equityArray, 0, i); TimeSeriesCollection dataset = new TimeSeriesCollection(equity); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false); chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false); chart.setBorderVisible(true); chart.getXYPlot().setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.blue); chart.getXYPlot().setBackgroundPaint(Color.white); chart.getXYPlot().setRangeGridlinePaint(Color.gray); chart.getXYPlot().setDomainGridlinePaint(Color.gray); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ChartUtilities.writeChartAsPNG(baos, chart, 320, 180); baos.flush(); this.equityChartByteArray = baos.toByteArray(); } catch (IOException e) { throw e; } }
From source file:org.zaproxy.zap.extension.customFire.ScanProgressDialog.java
/** * //from w w w. j av a 2 s .com */ private void initialize() { this.setSize(new Dimension(580, 504)); if (site != null) { this.setTitle("Scann Progress"); } JTabbedPane tabbedPane = new JTabbedPane(); JPanel tab1 = new JPanel(); tab1.setLayout(new GridBagLayout()); JPanel hostPanel = new JPanel(); hostPanel.setLayout(new GridBagLayout()); hostPanel.add(new JLabel("Host:"), LayoutHelper.getGBC(0, 0, 1, 0.4D)); hostPanel.add(getHostSelect(), LayoutHelper.getGBC(1, 0, 1, 0.6D)); tab1.add(hostPanel, LayoutHelper.getGBC(0, 0, 3, 1.0D, 0.0D)); tab1.add(getJScrollPane(), LayoutHelper.getGBC(0, 1, 3, 1.0D, 1.0D));//* tab1.add(new JLabel(), LayoutHelper.getGBC(0, 1, 1, 1.0D, 0.0D)); // spacer tab1.add(getCloseButton(), LayoutHelper.getGBC(1, 2, 1, 0.0D, 0.0D)); tab1.add(new JLabel(), LayoutHelper.getGBC(2, 1, 1, 1.0D, 0.0D)); // spacer tabbedPane.insertTab("Progress", null, tab1, null, 0); this.add(tabbedPane); int mins = extension.getScannerParam().getMaxChartTimeInMins(); if (mins > 0) { // Treat zero mins as disabled JPanel tab2 = new JPanel(); tab2.setLayout(new GridBagLayout()); this.seriesTotal = new TimeSeries("TotalResponses"); // Name not shown, so no need to i18n final TimeSeriesCollection dataset = new TimeSeriesCollection(this.seriesTotal); this.series100 = new TimeSeries("1xx"); this.series200 = new TimeSeries("2xx"); this.series300 = new TimeSeries("3xx"); this.series400 = new TimeSeries("4xx"); this.series500 = new TimeSeries("5xx"); this.seriesTotal.setMaximumItemAge(mins * 60); this.series100.setMaximumItemAge(mins * 60); this.series200.setMaximumItemAge(mins * 60); this.series300.setMaximumItemAge(mins * 60); this.series400.setMaximumItemAge(mins * 60); this.series500.setMaximumItemAge(mins * 60); dataset.addSeries(series100); dataset.addSeries(series200); dataset.addSeries(series300); dataset.addSeries(series400); dataset.addSeries(series500); chart = createChart(dataset);//* // Set up some vaguesly sensible colours chart.getXYPlot().getRenderer(0).setSeriesPaint(0, Color.BLACK); // Totals chart.getXYPlot().getRenderer(0).setSeriesPaint(1, Color.ORANGE); // 100: Info chart.getXYPlot().getRenderer(0).setSeriesPaint(2, Color.GREEN); // 200: OK chart.getXYPlot().getRenderer(0).setSeriesPaint(3, Color.BLUE); // 300: Info chart.getXYPlot().getRenderer(0).setSeriesPaint(4, Color.YELLOW); // 400: Bad req chart.getXYPlot().getRenderer(0).setSeriesPaint(5, Color.RED); // 500: Internal error chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(5.0f)); // Totals chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 100: Info chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 200: OK chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 300: Info chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 400: Bad req chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 500: Internal error final ChartPanel chartPanel = new ChartPanel(chart); tab2.add(chartPanel, LayoutHelper.getGBC(0, 0, 1, 1.0D, 1.0D)); tabbedPane.insertTab("ResponseCharts", null, tab2, null, 1); } // Stop the updating thread when the window is closed this.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { stopThread = true; } }); }
From source file:Operacional.Janela2.java
private IntervalXYDataset updateDataset(List<String> l, String d) { IntervalXYDataset i;// w ww. j ava 2 s .co m TimeSeries timeseries = new TimeSeries("Recebimento", "Year", "Count"); String[] aux; if (d.equals("ano")) { try { System.out.println("AQUI"); for (String s : l) { aux = splitAno(s); System.out.println(aux[0] + " " + aux[1]); timeseries.add(new Year(Integer.parseInt(aux[0])), Float.parseFloat(aux[1])); } } catch (Exception exception) { System.err.println(exception.getMessage()); } } else { try { System.out.println("AQUI"); for (String s : l) { aux = splitMes(s); System.out.println(aux[0] + " " + aux[1] + " " + aux[2]); timeseries.add(new Month(Integer.parseInt(aux[0]), Integer.parseInt(aux[1])), Float.parseFloat(aux[2])); } } catch (Exception exception) { System.err.println(exception.getMessage()); } } TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries); return timeseriescollection; }
From source file:de.tsystems.mms.apm.performancesignature.ui.PerfSigBuildActionResultsDisplay.java
public void doSummarizerGraph(final StaplerRequest request, final StaplerResponse response) throws IOException { final Graph graph = new GraphImpl(request, getBuild().getTimestamp().getTimeInMillis()) { @Override//from w ww .ja va 2 s . c o m protected TimeSeriesCollection createDataSet() { String measure = request.getParameter("measure"); String chartDashlet = request.getParameter("chartdashlet"); String testCase = request.getParameter("testcase"); TimeSeries timeSeries = new TimeSeries(chartDashlet, Second.class); DashboardReport dashboardReport = getDashBoardReport(testCase); Measure m = dashboardReport.getMeasure(chartDashlet, measure); if (m == null || m.getMeasurements() == null) { return null; } for (Measurement measurement : m.getMeasurements()) { timeSeries.add(new Second(new Date(measurement.getTimestamp())), measurement.getMetricValue(m.getAggregation())); } return new TimeSeriesCollection(timeSeries); } }; graph.doPng(request, response); }
From source file:name.wramner.jmstools.analyzer.DataProvider.java
/** * Get a base64-encoded image for inclusion in an img tag with a chart with message flight times. * * @return chart as base64 string./*from w ww . ja v a 2 s . c om*/ */ public String getBase64EncodedFlightTimeMetricsImage() { TimeSeries timeSeries50p = new TimeSeries("Median"); TimeSeries timeSeries95p = new TimeSeries("95 percentile"); TimeSeries timeSeriesMax = new TimeSeries("Max"); for (FlightTimeMetrics m : getFlightTimeMetrics()) { Minute minute = new Minute(m.getPeriod()); timeSeries50p.add(minute, m.getMedian()); timeSeries95p.add(minute, m.getPercentile95()); timeSeriesMax.add(minute, m.getMax()); } TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(timeSeries50p); timeSeriesCollection.addSeries(timeSeries95p); timeSeriesCollection.addSeries(timeSeriesMax); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { JFreeChart chart = ChartFactory.createTimeSeriesChart("Flight time", "Time", "ms", timeSeriesCollection); chart.getPlot().setBackgroundPaint(Color.WHITE); ChartUtilities.writeChartAsPNG(bos, chart, 1024, 500); } catch (IOException e) { throw new UncheckedIOException(e); } return "data:image/png;base64," + Base64.getEncoder().encodeToString(bos.toByteArray()); }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
public final String chartJobCount() throws Exception { final Calendar calendarToday = CalendarUtils.getCalendarWithoutTime(); final Calendar calendar30 = CalendarUtils.getCalendarWithoutTime(); calendar30.add(Calendar.MONTH, -36); final List<JobCountPerDay> jobCountPerDayList = jobService.getJobCountPerDayAndPeriod(calendar30.getTime(), calendarToday.getTime());//from w w w . j av a 2 s . com final TimeSeries hitsPerDayData = new TimeSeries("Hits", Day.class); final XYDataset hitsPerDayDataset = new TimeSeriesCollection(hitsPerDayData); this.chart = ChartFactory.createTimeSeriesChart("", super.getText("class.ShowStatisticsAcion.chart.job.count.caption"), "", hitsPerDayDataset, false, true, false); final XYPlot xyplot = (XYPlot) this.chart.getPlot(); for (JobCountPerDay jobCountPerDay : jobCountPerDayList) { final Day day = new Day(jobCountPerDay.getJobDate()); if (jobCountPerDay.getAutomaticallyCleaned()) { final Marker originalEnd = new ValueMarker(day.getFirstMillisecond()); originalEnd.setPaint(new Color(0, 80, 138, 150)); float[] dashPattern = { 6, 2 }; originalEnd.setStroke( new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); originalEnd.setLabel("C"); originalEnd.setAlpha(0.1F); xyplot.addDomainMarker(originalEnd); } hitsPerDayData.add(day, jobCountPerDay.getTotalNumberOfJobs()); } chart.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(false); xyitemrenderer.setSeriesPaint(0, new Color(244, 66, 0)); } DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setAutoRange(true); dateaxis.setAutoTickUnitSelection(true); NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return SUCCESS; }