List of usage examples for org.jfree.data.time TimeSeries add
public void add(RegularTimePeriod period, Number value)
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * A test to cover bug 3445507./* w w w . j av a 2 s.com*/ */ @Test public void testBug3445507() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2011), null); s1.add(new Year(2012), null); TimeSeries s2 = new TimeSeries("S2"); s2.add(new Year(2011), 5.0); s2.add(new Year(2012), 6.0); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); List keys = new ArrayList(); keys.add("S1"); keys.add("S2"); Range r = dataset.getRangeBounds(keys, new Range(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), false); assertEquals(5.0, r.getLowerBound(), EPSILON); assertEquals(6.0, r.getUpperBound(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
@Test public void testGetRangeBounds2() { TimeZone tzone = TimeZone.getTimeZone("Europe/London"); Calendar calendar = new GregorianCalendar(tzone, Locale.UK); calendar.clear();/*from w w w . ja va2s.c o m*/ calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0); long start = calendar.getTimeInMillis(); calendar.clear(); calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0); long end = calendar.getTimeInMillis(); Range range = new Range(start, end); TimeSeriesCollection collection = new TimeSeriesCollection(tzone); assertNull(collection.getRangeBounds(Collections.EMPTY_LIST, range, true)); TimeSeries s1 = new TimeSeries("S1"); s1.add(new Day(24, 2, 2014), 10.0); collection.addSeries(s1); assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true)); collection.setXPosition(TimePeriodAnchor.MIDDLE); assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true)); collection.setXPosition(TimePeriodAnchor.END); assertNull(collection.getRangeBounds(Arrays.asList("S1"), range, true)); }
From source file:com.ace.capitalflows.ui.frame.chart.NianYdChart.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset./*from www . j a v a2 s. c om*/ */ private XYDataset createDataset() { final TimeSeries ydResi = new TimeSeries("YdResidual"); for (int i = 0; dataArray[i] != null && i < dataArray.length - 1; i++) { final String nianYd = (String) dataArray[i][0]; final int year = CommenUtils.parseNian(nianYd); final int m = CommenUtils.parseJDORYD(nianYd); ydResi.add(new Month(m, year), NumberUtils.toDouble((String) dataArray[i][1])); } // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(ydResi); return dataset; }
From source file:org.apache.phoenix.pherf.result.impl.ImageResultHandler.java
@Override public synchronized void write(Result result) throws Exception { TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); int rowCount = 0; int maxLegendCount = 20; int chartDimension = 1100; ResultValue<DataModelResult> resultValue = result.getResultValues().get(0); DataModelResult dataModelResult = resultValue.getResultValue(); for (ScenarioResult scenarioResult : dataModelResult.getScenarioResult()) { for (QuerySetResult querySetResult : scenarioResult.getQuerySetResult()) { for (QueryResult queryResult : querySetResult.getQueryResults()) { for (ThreadTime tt : queryResult.getThreadTimes()) { TimeSeries timeSeries = new TimeSeries( queryResult.getStatement() + " :: " + tt.getThreadName()); rowCount++;/*from www.j a v a 2s . c o m*/ synchronized (tt.getRunTimesInMs()) { for (RunTime rt : tt.getRunTimesInMs()) { if (rt.getStartTime() != null) { timeSeries.add(new Millisecond(rt.getStartTime()), rt.getElapsedDurationInMs()); } } } timeSeriesCollection.addSeries(timeSeries); } } } } boolean legend = rowCount > maxLegendCount ? false : true; JFreeChart chart = ChartFactory.createTimeSeriesChart(dataModelResult.getName(), "Time", "Query Time (ms)", timeSeriesCollection, legend, true, false); StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); chart.getXYPlot().setRenderer(renderer); chart.getXYPlot().setBackgroundPaint(Color.WHITE); chart.getXYPlot().setRangeGridlinePaint(Color.BLACK); for (int i = 0; i < rowCount; i++) { chart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(3f)); } try { ChartUtilities.saveChartAsJPEG(new File(resultFileName), chart, chartDimension, chartDimension); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.sourceforge.openforecast.examples.ExponentialSmoothingChartDemo.java
/** * Use the given forecasting model to produce a TimeSeries object * representing the periods startIndex through endIndex, and containing * the forecast values produced by the model. * @param model the forecasting model to use to generate the forecast * series./*from w w w. jav a2s . c om*/ * @param initDataSet data set to use to initialize the forecasting model. * @param startIndex the index of the first data point to use from the * set of potential forecast values. * @param endIndex the index of the last data point to use from the set * of potential forecast values. * @param title a title to give to the TimeSeries created. */ private TimeSeries getForecastTimeSeries(ForecastingModel model, DataSet initDataSet, int startIndex, int endIndex, String title) { // Initialize the forecasting model model.init(initDataSet); // Get range of data required for forecast DataSet fcDataSet = getDataSet(fc, startIndex, endIndex); // Obtain forecast values for the forecast data set model.forecast(fcDataSet); // Create a new TimeSeries TimeSeries series = new TimeSeries(title, fc.getTimePeriodClass()); // Iterator through the forecast results, adding to the series Iterator it = fcDataSet.iterator(); while (it.hasNext()) { DataPoint dp = (DataPoint) it.next(); int index = (int) dp.getIndependentValue("t"); series.add(fc.getTimePeriod(index), dp.getDependentValue()); } return series; }
From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer.java
public JFreeChart renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon) { String[] observedProperties;//from w w w .j ava 2 s . c o m // which observedProperty has been used?: ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty"); if (observedPropertyPS.hasMultipleSpecifiedValues()) { observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class); } else if (observedPropertyPS.hasSingleSpecifiedValue()) { observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() }; } else { throw new IllegalArgumentException("no observedProperties found."); } phenomenon = observedProperties[0]; String[] foiIdArray = paramCon.getParameterShellWithServiceSidedName("featureOfInterest") .getSpecifiedTypedValueArray(String[].class); TimeSeriesCollection dataset = new TimeSeriesCollection(); ObservationSeriesCollection tuples4FOI = new ObservationSeriesCollection(observationCollection, foiIdArray, observedProperties, true); for (String featureID : foiIdArray) { Map<ITimePosition, ObservedValueTuple> tupleMap = tuples4FOI.getAllTuples(featureID); // for each selected feature construct a new TimeSeries: TimeSeries timeSeries = new TimeSeries(featureID, Second.class); if (tupleMap != null) { for (ITimePosition timePos : tupleMap.keySet()) { ObservedValueTuple tuple = tupleMap.get(timePos); double measurement = (Double) tuple.getValue(0); timeSeries.add(new Second(new Float(timePos.getSecond()).intValue(), timePos.getMinute(), timePos.getHour(), timePos.getDay(), timePos.getMonth(), new Long(timePos.getYear()).intValue()), measurement); } dataset.addSeries(timeSeries); } } dataset.setDomainIsPointsInTime(true); return drawChart(dataset); }
From source file:edu.indiana.htrc.visual.HTRCSeriesChartDrawer.java
@Override public File draw() { Set<String> key_set = input_map.keySet(); Iterator<String> iter = key_set.iterator(); TimeSeries accessSeries = new TimeSeries(dataset_label, Day.class); while (iter.hasNext()) { String dateStr = iter.next(); // yyyy-MM-dd int value = input_map.get(dateStr); Date date = null;/*w w w.j a v a 2s . co m*/ try { date = format.parse(dateStr); System.out.println(date); cal.setTime(date); accessSeries.add( new Day(cal.get(Calendar.DATE), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)), value); } catch (ParseException e) { e.printStackTrace(); } } TimeSeriesCollection series_dataset = new TimeSeriesCollection(); series_dataset.addSeries(accessSeries); JFreeChart series_chart = ChartFactory.createTimeSeriesChart(chart_name, x_axis_label, y_axis_label, series_dataset, true, true, false); File img = new File("../webapps/HTRC-UI-AuditAnalyzer/images/" + System.currentTimeMillis() + ".jpg"); try { ChartUtilities.saveChartAsJPEG(img, series_chart, 1400, 600); } catch (IOException e) { e.printStackTrace(); } return img; }
From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java
private JFreeChart getMemoryChart(int intervalSize, List<MemoryData> memory) { if (null == memory || memory.isEmpty()) { return null; }/* w ww. j a v a 2s . c om*/ JFreeChart chart; TimeSeries freeSeries = new TimeSeries("Free"); TimeSeries maxSeries = new TimeSeries("Max"); TimeSeries totalSeries = new TimeSeries("Total"); memory.remove(memory.size() - 1); for (MemoryData memoryEntry : memory) { freeSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getFreeMemory()); maxSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getMaxMemory()); totalSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getTotalMemory()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(freeSeries); dataset.addSeries(maxSeries); dataset.addSeries(totalSeries); chart = ChartFactory.createTimeSeriesChart("eID Trust Service Memory Usage History", "Time (interval size " + intervalSize + " msec)", "Memory", dataset, true, false, false); chart.addSubtitle(new TextTitle( memory.get(0).getDate().toString() + " - " + memory.get(memory.size() - 1).getDate().toString())); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); plot.setRenderer(renderer); return chart; }
From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java
private XYDataset createDataset(ArrayList<Sensor> sensors) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); for (int i = 0; i < sensors.size(); i++) { Sensor current_sensor = sensors.get(i); final TimeSeries s1 = new TimeSeries("Sensor " + i, Hour.class); for (int j = 0; j < current_sensor.getDimensions(); j++) { LocalDateTime current_record_time = current_sensor.getInitial_record_time().plusHours(j); s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(), current_record_time.getMonthValue(), current_record_time.getYear()), current_sensor.getMeasurement(j)); }/*from w ww . j av a2s . co m*/ dataset.addSeries(s1); } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void addStart(TimeSeriesCollection chartSeries, String name, TsPeriod start) { TsData ts = history_.series(name, start); if (ts != null) { TimeSeries chartTs = new TimeSeries(""); int pos = start.minus(ts.getStart()); Day day = new Day(start.middle()); chartTs.add(day, ts.get(pos)); chartSeries.addSeries(chartTs);/*from w w w.j a v a 2 s . co m*/ } }