List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name)
From source file:org.jfree.data.time.MovingAverage.java
/** * Creates a new {@link TimeSeries} containing moving average values for * the given series. If the series is empty (contains zero items), the * result is an empty series.//from ww w .j av a 2 s . c o m * * @param source the source series. * @param name the name of the new series. * @param periodCount the number of periods used in the average * calculation. * @param skip the number of initial periods to skip. * * @return The moving average series. */ public static TimeSeries createMovingAverage(TimeSeries source, String name, int periodCount, int skip) { ParamChecks.nullNotPermitted(source, "source"); if (periodCount < 1) { throw new IllegalArgumentException("periodCount must be greater " + "than or equal to 1."); } TimeSeries result = new TimeSeries(name); if (source.getItemCount() > 0) { // if the initial averaging period is to be excluded, then // calculate the index of the // first data item to have an average calculated... long firstSerial = source.getTimePeriod(0).getSerialIndex() + skip; for (int i = source.getItemCount() - 1; i >= 0; i--) { // get the current data item... RegularTimePeriod period = source.getTimePeriod(i); long serial = period.getSerialIndex(); if (serial >= firstSerial) { // work out the average for the earlier values... int n = 0; double sum = 0.0; long serialLimit = period.getSerialIndex() - periodCount; int offset = 0; boolean finished = false; while ((offset < periodCount) && (!finished)) { if ((i - offset) >= 0) { TimeSeriesDataItem item = source.getRawDataItem(i - offset); RegularTimePeriod p = item.getPeriod(); Number v = item.getValue(); long currentIndex = p.getSerialIndex(); if (currentIndex > serialLimit) { if (v != null) { sum = sum + v.doubleValue(); n = n + 1; } } else { finished = true; } } offset = offset + 1; } if (n > 0) { result.add(period, sum / n); } else { result.add(period, null); } } } } return result; }
From source file:com.tencent.wstt.apt.chart.AbstractRealTimeLineChart.java
/** * ??.// w w w . j a v a 2 s .c o m * * @return ??. */ public boolean initDataset(String[] objects, String[] datas) { if (objects == null || datas == null || objects.length == 0 || datas.length == 0) { return false; } objectNum = objects.length; dataNum = datas.length; dataset.removeAllSeries(); if (datas.length == 1) { for (int i = 0; i < objectNum; i++) { // ?? chart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(Constant.LINE_WIDTH)); tsList.add(new TimeSeries(objects[i])); tsEnableList.add(true); dataset.addSeries(tsList.get(i)); } } else { for (int i = 0; i < objectNum; i++) { for (int j = 0; j < dataNum; j++) { int index = dataNum * i + j; //?? chart.getXYPlot().getRenderer().setSeriesStroke(index, new BasicStroke(Constant.LINE_WIDTH)); tsList.add(new TimeSeries(objects[i] + "_" + datas[j])); tsEnableList.add(true); dataset.addSeries(tsList.get(index)); } } } return true; }
From source file:graficoComparacion.graficaCompa.java
public void graficaCompa2() { //sxy.add(x[0], y[0]); TimeSeries s2 = new TimeSeries("Entrenamiento Actual"); /////////////// s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); ////////////////////////////////////// datos.addSeries(s2);/*from w ww.j a va 2s .c o m*/ }
From source file:ecg.ecgshow.ECGShowUI.java
private void createECGData(long timeZone) { ECGData = new JPanel(new GridLayout(LEAD_COUNT, 1)); dateAxises = new DateAxis[LEAD_COUNT]; ECGSeries = new TimeSeries[LEAD_COUNT * 2]; for (int i = 0; i < LEAD_COUNT; i++) { TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); //XYDataset TimeSeriesCollection ECGSeries[i] = new TimeSeries("?" + (i + 1)); ECGSeries[i].setMaximumItemCount(500); ECGSeries[i + LEAD_COUNT] = new TimeSeries(""); ECGSeries[i + LEAD_COUNT].setMaximumItemAge(timeZone); ECGSeries[i + LEAD_COUNT].setMaximumItemCount(2); timeseriescollection.addSeries(ECGSeries[i]); timeseriescollection.addSeries(ECGSeries[i + LEAD_COUNT]); //DateAxis dateaxis = new DateAxis("Time"); dateAxises[i] = new DateAxis(""); dateAxises[i].setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016))); dateAxises[i].setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018))); dateAxises[i].setTickLabelsVisible(true); dateAxises[i].setVisible(false); //NumberAxis numberaxis = new NumberAxis("ecg"); NumberAxis numberaxis = new NumberAxis("ecg"); numberaxis.setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016))); numberaxis.setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018))); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setVisible(false);/*from www .j ava2 s. c om*/ numberaxis.setLowerBound(1500D); numberaxis.setUpperBound(3000D); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.GREEN); // xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2)); xylineandshaperenderer.setSeriesPaint(1, Color.LIGHT_GRAY); // xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(5)); XYPlot xyplot = new XYPlot(timeseriescollection, dateAxises[i], numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.LIGHT_GRAY); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setBackgroundPaint(Color.BLACK); JFreeChart jfreechart = new JFreeChart(xyplot); jfreechart.setBackgroundPaint(new Color(237, 237, 237));//? jfreechart.getLegend().setVisible(false); ChartPanel chartpanel = new ChartPanel(jfreechart, (int) (WIDTH * 46 / 100), (int) (HEIGHT * 17 / 100), 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, true, false, false); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0) //??0 , BorderFactory.createEmptyBorder() //???? )); chartpanel.setMouseZoomable(false); //? ECGData.add(chartpanel); } }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
/** * Creates a sample dataset.// w w w. ja v a 2 s . com * * @return A dataset. */ private static XYDataset createDataset() { TimeSeries series1 = new TimeSeries("Division A"); series1.add(new Year(2005), 1520); series1.add(new Year(2006), 1132); series1.add(new Year(2007), 450); series1.add(new Year(2008), 620); TimeSeries series2 = new TimeSeries("Division B"); series2.add(new Year(2005), 1200); series2.add(new Year(2006), 1300); series2.add(new Year(2007), 640); series2.add(new Year(2008), 520); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); return dataset; }
From source file:com.jbombardier.reports.ReportGenerator.java
private static void generatePathView(File folder, String phase, String distinctPath, List<CapturedStatistic> capturedStatistics) { HTMLBuilder2 builder = new HTMLBuilder2(); builder.getHead().css("box.css"); builder.getHead().css("table.css"); HTMLBuilder2.Element bodyx = builder.getBody(); final HTMLBuilder2.Element content = bodyx.div("wide-box"); TimeSeries series = new TimeSeries(distinctPath); TimeSeriesCollection data = new TimeSeriesCollection(); data.addSeries(series);/* ww w . ja va2s . c o m*/ NumberFormat nf = NumberFormat.getInstance(); try { for (CapturedStatistic capturedStatistic : capturedStatistics) { if (capturedStatistic.getPath().equals(distinctPath)) { series.addOrUpdate(new Second(new Date(capturedStatistic.getTime())), nf.parse(capturedStatistic.getValue())); } } } catch (ParseException nfe) { // Skip this one, its not numeric } if (series.getItemCount() > 0) { final String imageName = StringUtils.format("phase-{}-path-{}.png", phase, distinctPath.replace('/', '-')); content.image(imageName); final File file = new File(folder, imageName); render(StringUtils.format("phase-{}-path-{}.html", phase, distinctPath.replace('/', '-')), data, file); } builder.toFile(new File(folder, StringUtils.format("phase-{}-path-{}.html", phase, distinctPath.replace('/', '-')))); }
From source file:name.wramner.jmstools.analyzer.DataProvider.java
/** * Get a base64-encoded image for inclusion in an img tag with a chart with kilobytes per minute produced and * consumed./*from w w w. j ava 2 s.c o m*/ * * @return chart as base64 string. */ public String getBase64BytesPerMinuteImage() { TimeSeries timeSeriesConsumed = new TimeSeries("Consumed"); TimeSeries timeSeriesProduced = new TimeSeries("Produced"); TimeSeries timeSeriesTotal = new TimeSeries("Total"); for (PeriodMetrics m : getMessagesPerMinute()) { Minute minute = new Minute(m.getPeriodStart()); timeSeriesConsumed.add(minute, m.getConsumedBytes() / 1024); timeSeriesProduced.add(minute, m.getProducedBytes() / 1024); timeSeriesTotal.add(minute, m.getTotalBytes() / 1024); } TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(timeSeriesConsumed); timeSeriesCollection.addSeries(timeSeriesProduced); timeSeriesCollection.addSeries(timeSeriesTotal); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { JFreeChart chart = ChartFactory.createTimeSeriesChart("Kilobytes per minute", "Time", "Bytes (k)", 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:siris.applications.basicexample.TimeSeriesChartDemo1.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.//from ww w . j a va2 s .c o m */ private static XYDataset createDataset() { s1 = new TimeSeries("L&G European Index Trust"); s1.add(new Month(2, 2001), 181.8); TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); s2.add(new Month(2, 2001), 129.6); s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); s2.add(new Month(11, 2001), 106.1); s2.add(new Month(12, 2001), 110.3); s2.add(new Month(1, 2002), 111.7); s2.add(new Month(2, 2002), 111.0); s2.add(new Month(3, 2002), 109.6); s2.add(new Month(4, 2002), 113.2); s2.add(new Month(5, 2002), 111.6); s2.add(new Month(6, 2002), 108.8); s2.add(new Month(7, 2002), 101.6); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
From source file:TimeSeriesChartDemo1.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.//from w ww .ja va 2 s .c o m */ private static XYDataset createDataset() { TimeSeries s1 = new TimeSeries("L&G European Index Trust"); 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); /* TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); s2.add(new Month(2, 2001), 129.6); s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); s2.add(new Month(11, 2001), 106.1); s2.add(new Month(12, 2001), 110.3); s2.add(new Month(1, 2002), 111.7); s2.add(new Month(2, 2002), 111.0); s2.add(new Month(3, 2002), 109.6); s2.add(new Month(4, 2002), 113.2); s2.add(new Month(5, 2002), 111.6); s2.add(new Month(6, 2002), 108.8); s2.add(new Month(7, 2002), 101.6);*/ // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); //dataset.addSeries(s2); return dataset; }
From source file:org.squale.squaleweb.util.graph.AreaMaker.java
/** * Ajoute les valeurs d'une courbe//from w ww .j av a 2s .c o m * * @param pName nom associ la future courbe * @param pValues Map contenant en cl des date (java.util.Date) et en valeurs des nombres (Number) */ public void addCurve(String pName, Map pValues) { TimeSeries timeSeries = new TimeSeries(pName); Set keys = pValues.keySet(); Iterator it = keys.iterator(); double acc = 0; while (it.hasNext()) { Date date = (Date) it.next(); Day day = new Day(date); // On cumule les rsultats acc += ((Number) pValues.get(date)).doubleValue(); timeSeries.addOrUpdate(day, new Double(acc)); } mDataSet.addSeries(timeSeries); }