List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, Class timePeriodClass)
From source file:org.jfree.chart.demo.InternalFrameDemo.java
/** * Creates a sample dataset./* w ww. j a va 2 s .c om*/ * * @param name the dataset name. * @param base the starting value. * @param start the starting period. * @param count the number of values to generate. * * @return The dataset. */ private XYDataset createDataset(final String name, final double base, final RegularTimePeriod start, final int count) { final TimeSeries series = new TimeSeries(name, start.getClass()); RegularTimePeriod period = start; double value = base; for (int i = 0; i < count; i++) { series.add(period, value); period = period.next(); value = value * (1 + (Math.random() - 0.495) / 10.0); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); return dataset; }
From source file:eu.hydrologis.jgrass.charting.impl.JGrassXYTimeLineChart.java
public JGrassXYTimeLineChart(List<String> chartTitles, List<double[][]> chartValues, Class<?> timeClass) { try {//from w w w .ja va 2 s. co m chartSeries = new TimeSeries[chartValues.size()]; constructor = (Constructor<RegularTimePeriod>) timeClass.getConstructor(Date.class); for (int i = 0; i < chartTitles.size(); i++) { final String title = chartTitles.get(i); final double[][] values = chartValues.get(i); chartSeries[i] = new TimeSeries(title, timeClass); for (int j = 0; j < values[0].length; j++) { // important: the data matrix has to be passed as two rows (not // two columns) double val = values[1][j]; if (isNovalue(val)) continue; chartSeries[i].add(constructor.newInstance(new Date((long) values[0][j])), val); } } lineDataset = new TimeSeriesCollection(); for (int i = 0; i < chartSeries.length; i++) { lineDataset.addSeries(chartSeries[i]); } lineDataset.setXPosition(TimePeriodAnchor.MIDDLE); lineDataset.setDomainIsPointsInTime(true); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.hydrologis.jgrass.charting.impl.JGrassXYTimeBarChart.java
public JGrassXYTimeBarChart(List<String> chartTitles, List<double[][]> chartValues, Class<?> timeClass, double barWidth) { try {/*from w w w. ja v a2 s . com*/ chartSeries = new TimeSeries[chartValues.size()]; constructor = (Constructor<RegularTimePeriod>) timeClass.getConstructor(Date.class); for (int i = 0; i < chartTitles.size(); i++) { final String title = chartTitles.get(i); final double[][] values = chartValues.get(i); chartSeries[i] = new TimeSeries(title, timeClass); for (int j = 0; j < values[0].length; j++) { // important: the data matrix has to be passed as two rows (not // two columns) double val = values[1][j]; if (isNovalue(val)) continue; chartSeries[i].add(constructor.newInstance(new Date((long) values[0][j])), val); } } lineDataset = new TimeSeriesCollection(); for (int i = 0; i < chartSeries.length; i++) { lineDataset.addSeries(chartSeries[i]); } lineDataset.setXPosition(TimePeriodAnchor.MIDDLE); lineDataset.setDomainIsPointsInTime(true); if (barWidth != -1) dataset = new XYBarDataset(lineDataset, barWidth); } catch (Exception e) { ChartPlugin.log("ChartPlugin problem", e); //$NON-NLS-1$ } }
From source file:de.fischer.thotti.reportgen.diagram.ChartGenerator.java
public ChartMetaData generateSingleVariantsChart(final String testId, String jvmArgsId, String paramGrpId) { String variantId = String.format("%s-%s-%s", testId, jvmArgsId, paramGrpId); File chartFile;// ww w .j a v a 2 s . co m try { final TimeSeriesCollection collection = new TimeSeriesCollection(); String chartTitle = String.format("%s-%s-%s", testId, jvmArgsId, paramGrpId); String svgFilename = String.format("%s-%s-%s.svg", testId, jvmArgsId, paramGrpId); chartFile = new File(baseDir, svgFilename); TimeSeries series = new TimeSeries(String.format("Average of %s", variantId), Day.class); TimeSeries mediaSeries = new TimeSeries(String.format("Median of %s", variantId), Day.class); List<NDResultEntity> results = persistenceHelper.findAllResultsForVariant(testId, jvmArgsId, paramGrpId); SortedSet<NDResultEntity> sortedSet = new TreeSet<NDResultEntity>( new TestVariantModel.DateComparator()); sortedSet.addAll(results); Iterator<Measurement> itr = new AverageDayCombinerIterator(sortedSet.iterator()); while (itr.hasNext()) { Measurement singleResult = itr.next(); Date startDate = singleResult.getPointInTime(); double time = singleResult.getDuration(); double t2 = convertMilliSecsToSeconds(time); series.add(new Day(startDate), t2); } collection.addSeries(series); Iterator<DatePoint> medianItr = new MedianIterator(sortedSet.iterator()); while (medianItr.hasNext()) { DatePoint singleResult = medianItr.next(); Date startDate = singleResult.getPointInTime(); double value = convertMilliSecsToSeconds(singleResult.getValue()); mediaSeries.add(new Day(startDate), value); } collection.addSeries(mediaSeries); final JFreeChart chart = createChart(chartTitle, collection); saveChartAsSVG(chart, svgFilename); System.out.println(String.format("Written %s", chartFile.toString())); return new ChartMetaData().withFilename(chartFile.getName()).withWidth(DEFAULT_CHAR_WIDTH) .withHeight(DEFAULT_CHAR_HEIGHT).withFormat("SVG"); } catch (IOException ioe) { // @todo Throw an better exception! ioe.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return null; }
From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo1.java
/** * Creates a sample dataset./*from w ww. j a v a 2 s . c o m*/ * * @param name the dataset name. * @param base the starting value. * @param start the starting period. * @param count the number of values to generate. * * @return The dataset. */ protected XYDataset createDataset(boolean isDemo) { if (isDemo) { String name = "Random 1"; double base = 100.0; RegularTimePeriod start = new Minute(); int count = 200; TimeSeries series = new TimeSeries(name, start.getClass()); RegularTimePeriod period = start; double value = base; for (int i = 0; i < count; i++) { series.add(period, value); period = period.next(); value = value * (1 + (Math.random() - 0.495) / 10.0); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); return dataset; } else { super.setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; double[][] y = new double[xyLength][dependentVarLength]; int[][] skipy = new int[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) if (depValues[i][index] == null || depValues[i][index].length() == 0) skipy[i][index] = 1; else y[i][index] = Double.parseDouble(depValues[i][index]); // create the dataset... TimeSeriesCollection collection = new TimeSeriesCollection(); TimeSeries series; for (int ind = 0; ind < independentVarLength; ind++) { if (independentHeaders[ind].indexOf(":") != -1) series = new TimeSeries( independentHeaders[ind].substring(0, independentHeaders[ind].indexOf(":")), Minute.class); else series = new TimeSeries(independentHeaders[ind], Minute.class); //TimeSeries("Executions", "Year", "Count", Year.class); for (int i = 0; i < xyLength; i++) { if (x[i][ind] != null && y[i][ind] != 1) series.add(DateParser.parseMinute(x[i][ind]), y[i][ind]); } // collection.setDomainIsPointsInTime(false); collection.addSeries(series); } return collection; } }
From source file:com.mxgraph.examples.swing.chart.TimeSeriesChartDemo1.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.// www. java2s. com */ public static XYDataset createDataset() { TimeSeries s1 = new TimeSeries("L&G European Index Trust", Second.class); s1.add(new Second(30, new Minute()), 181.8); s1.add(new Second(10, new Minute()), 151.8); s1.add(new Second(20, new Minute()), 167.8); s1.add(new Second(37, new Minute()), 155.8); s1.add(new Second(45, new Minute()), 166.8); s1.add(new Second(24, new Minute()), 144.8); s1.add(new Second(6, new Minute()), 181.8); /* s1.add(new Second(1,1,1,1,3, 2001), 167.3); s1.add(new Second(3,3,3,3,4, 2001), 153.8); s1.add(new Second(5,5,5,5,5, 2001), 167.6); s1.add(new Second(6,6,6,6,6, 2001), 158.8); s1.add(new Second(7,7,7,7,7, 2001), 148.3); s1.add(new Second(8,8,8,8,8, 2001), 153.9); s1.add(new Second(9,9,9,9,9, 2001), 142.7); s1.add(new Second(10,10,8,8,8, 2001), 123.2); s1.add(new Second(1,1,1,1,11, 2001), 131.8); s1.add(new Second(1,2,3,4,12, 2001), 139.6); s1.add(new Second(5,2,4,2,1, 2002), 142.9); s1.add(new Second(5,6,5,6,2, 2002), 138.7);*/ // ****************************************************************** // 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); return dataset; }
From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java
/** * Initialize components// w ww .ja va2 s. c o m */ private void initialize() { usedDataTypeModel = new DefaultComboBoxModel(); usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_upload")); usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_download")); usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_upload")); usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_download")); usedGraphTypeModel = new DefaultComboBoxModel(); usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.used_and_available")); usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.used_only")); usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.available_only")); usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.average")); percentDataTypeModel = new DefaultComboBoxModel(); percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_upload")); percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_download")); percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_upload")); percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_download")); usedBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.used"), Hour.class); availableBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.available"), Hour.class); averageBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.average"), Hour.class); percentageBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.percentage"), Hour.class); }
From source file:in.BBAT.presenter.DualAxisDemo2.java
/** * Creates a sample dataset./*from ww w . j av a 2 s. c om*/ * * @return The dataset. */ private XYDataset createDataset1() { final TimeSeries s2 = new TimeSeries("Memory", Millisecond.class); for (MemoryEntity ent : ScreenShotView.testCase.getMemoryUsageValues()) { s2.addOrUpdate(new Millisecond(new Date(ent.getTime())), ent.getPercent()); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s2); return dataset; }
From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo3.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return the dataset.//from w w w .j av a 2 s. c om */ protected XYDataset createDataset(boolean isDemo) { if (isDemo) { chartTitle = "Legal & General Unit Trust Prices"; domainLabel = "Date"; rangeLabel = "Price Per Unit"; TimeSeries s1 = new TimeSeries("L&G European Index Trust", Month.class); 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", Month.class); 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); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); // dataset.setDomainIsPointsInTime(true); return dataset; } else { super.setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; double[][] y = new double[xyLength][dependentVarLength]; int[][] skipy = new int[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) if (depValues[i][index] == null || depValues[i][index].length() == 0) skipy[i][index] = 1; else y[i][index] = Double.parseDouble(depValues[i][index]); // create the dataset... TimeSeriesCollection collection = new TimeSeriesCollection(); TimeSeries series; for (int ind = 0; ind < independentVarLength; ind++) { if (independentHeaders[ind].indexOf(":") != -1) series = new TimeSeries( independentHeaders[ind].substring(0, independentHeaders[ind].indexOf(":")), Month.class); else series = new TimeSeries(independentHeaders[ind], Month.class); //TimeSeries("Executions", "Year", "Count", Year.class); for (int i = 0; i < xyLength; i++) { if (x[i][ind] != null && y[i][ind] != 1) series.add(DateParser.parseMonth(x[i][ind]), y[i][ind]); } //collection.setDomainIsPointsInTime(false); collection.addSeries(series); } return collection; } }
From source file:org.jfree.chart.demo.TimeSeriesDemo12.java
/** * Creates a sample dataset./* ww w. j a v a 2s. c om*/ * * @return the dataset. */ private XYDataset createDataset() { final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.setDomainIsPointsInTime(true); final TimeSeries s1 = new TimeSeries("Series 1", Minute.class); s1.add(new Minute(0, 0, 7, 12, 2003), 1.2); s1.add(new Minute(30, 12, 7, 12, 2003), 3.0); s1.add(new Minute(15, 14, 7, 12, 2003), 8.0); final TimeSeries s2 = new TimeSeries("Series 2", Minute.class); s2.add(new Minute(0, 3, 7, 12, 2003), 0.0); s2.add(new Minute(30, 9, 7, 12, 2003), 0.0); s2.add(new Minute(15, 10, 7, 12, 2003), 0.0); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }