List of usage examples for org.jfree.chart ChartFactory createTimeSeriesChart
public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:org.n52.io.type.quantity.handler.img.ChartIoHandler.java
private XYPlot createChart(IoStyleContext styleContext) { String timespan = getTimespan(); DateTime end = new DateTime(timespan.split("/")[1]); String zoneName = getTimezone().getShortName(end.getMillis(), i18n.getLocale()); StringBuilder domainAxisLabel = new StringBuilder(i18n.get("msg.io.chart.time")); domainAxisLabel.append(" (").append(zoneName).append(")"); IoParameters parameters = getParameters(); boolean showLegend = parameters.isLegend(); jFreeChart = ChartFactory.createTimeSeriesChart(null, domainAxisLabel.toString(), i18n.get("msg.io.chart.value"), null, showLegend, false, true); return createPlotArea(jFreeChart); }
From source file:CargarEntrenamiento.grafica2.java
public void grafica1() { s1.add(new Month(2, 2001), 181.8); //s1.add(new Week(1, 1), null); 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); TimeSeries s3 = new TimeSeries("andres2255"); s3.add(new Month(2, 2001), 129.6); s3.add(new Month(10, 2001), 106.1); s3.add(new Month(1, 2002), 111.7); s3.add(new Month(2, 2002), 111.0); datos.addSeries(s1);/*from w w w. java 2 s . c o m*/ datos.addSeries(s2); datos.addSeries(s3); grafica = ChartFactory.createTimeSeriesChart("titulo", "etiquetas X", "etiquetaY", datos, true, true, false); /// grafica.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) grafica.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); }
From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java
/** * This function creates the measurement graph by using the JFreeChart * library. The X axis of the graph is in minutes. * //from ww w. ja va2 s .c om * @param plotList * plotlist to save. Xvalues must be stored in milliseconds. * @param associatedName * Name of the list * @param folderWhereResultsAreSaved * folder where results are saved * @param yLabel * Name of the y label * @param pictureFile * name of the file * @param yDivisor * use to divide measurements stored in the plotlist by yDivisor */ public static void generateGraphWithJFreeChart(PlotList plotList, String associatedName, String folderWhereResultsAreSaved, String yLabel, String pictureFile, float yDivisor) { // Create a new XYSeries // XYSeries are used to represent couples of (x,y) values. XYSeries data = new XYSeries(associatedName); int size = plotList.getSize(); if (size == 0) { // no element in graphics, exit //Logger.getLogger(this.getClass() ).warn("Nothing in graph"); return; } // Find the initial value of the time // Due to the fact that getX(i) <= getX(i+1), // min({0<=i<size / getX(i)}) = getX(0) long initialValue = plotList.getX(0); XYSeriesCollection series = new XYSeriesCollection(data); if (!plotList.getunit().equals("")) yLabel += " (" + plotList.getunit() + ")"; // Create a new XY graph. //JFreeChart chart = ChartFactory.createXYLineChart("", "Time", yLabel, series, PlotOrientation.VERTICAL, true, true, false); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time (min:sec)", yLabel, series, true, true, false); // Set the graph format XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); DateAxis axis = (DateAxis) plot.getDomainAxis(); //axis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 10)); RelativeDateFormat rdf = new RelativeDateFormat(initialValue); rdf.setSecondFormatter(new DecimalFormat("00")); axis.setDateFormatOverride(rdf); // Fill the JFreeChart object which will be used to create the Graph for (int i = 0; i < size; i++) { // xvalue must be in double xval = ((Long) plotList.getX(i)).doubleValue(); float yval = plotList.getY(i).floatValue() / yDivisor; // Logger.getLogger(this.getClass() ).debug(associatedName + " [" + (((Long) // plotList.getX(i)).floatValue() - initialValue) // / XDIVISOR +"] "+ yval); data.add(xval, yval); } ValueAxis rangeAxis = plot.getRangeAxis(); Long min = plotList.getMin(); Long max = plotList.getMax(); double diff = (max - min) * 0.02; if (diff == 0) diff = max * 0.0001; rangeAxis.setLowerBound((min - diff) / yDivisor); rangeAxis.setUpperBound((max + diff) / yDivisor); // Logger.getLogger(this.getClass() ).debug("(" + (min / yDivisor) * 0.98 + " - " // + (min / yDivisor) * 0.98 + ")"); // Logger.getLogger(this.getClass() ).debug("Bound = " + rangeAxis.getLowerBound() + " - " // + rangeAxis.getUpperBound()); // Logger.getLogger(this.getClass() ).debug("Margin = " + rangeAxis.getLowerMargin() + " - " // + rangeAxis.getUpperMargin()); // Logger.getLogger(this.getClass() ).debug("NB AXIS = " + plot.getRangeAxisCount()); // save the chart in a picture file. BufferedImage bufImage = chart.createBufferedImage(640, 480); File fichier = new File(pictureFile); try { if (!ImageIO.write(bufImage, "png", fichier)) { return; } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java
private JFreeChart createTimeSeriesChart(TimeSeriesCollection dataSet, Color color) { JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataSet, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRenderer().setSeriesPaint(0, color); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(0, 150);/*from ww w . j a v a 2 s. c om*/ ValueAxis xAxis = plot.getDomainAxis(); xAxis.setAutoRange(true); xAxis.setFixedAutoRange(5 * MINUTE); return chart; }
From source file:it.marcoberri.mbmeteo.action.chart.Get.java
/** * Processes requests for both HTTP/* w ww. ja va2s . c om*/ * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("start : " + this.getClass().getName()); final HashMap<String, String> params = getParams(request.getParameterMap()); final Integer dimy = Default.toInteger(params.get("dimy"), 600); final Integer dimx = Default.toInteger(params.get("dimx"), 800); final String from = Default.toString(params.get("from") + " 00:00:00", "1970-01-01 00:00:00"); final String to = Default.toString(params.get("to") + " 23:59:00", "2030-01-01 23:59:00"); final String field = Default.toString(params.get("field"), "outdoorTemperature"); request.getSession().setAttribute("from", params.get("from")); request.getSession().setAttribute("to", params.get("to")); final String cacheKey = getCacheKey(params); if (cacheReadEnable) { final Query q = ds.find(Cache.class); q.filter("cacheKey", cacheKey).filter("servletName", this.getClass().getName()); final Cache c = (Cache) q.get(); if (c == null) { log.info("cacheKey:" + cacheKey + " on servletName: " + this.getClass().getName() + " not found"); } if (c != null) { log.debug("get file from cache id: " + c.getGridId()); final GridFSDBFile imageForOutput = MongoConnectionHelper.getGridFS() .findOne(new ObjectId(c.getGridId())); if (imageForOutput != null) { ds.save(c); try { response.setHeader("Content-Length", "" + imageForOutput.getLength()); response.setHeader("Content-Disposition", "inline; filename=\"" + imageForOutput.getFilename() + "\""); final OutputStream out = response.getOutputStream(); final InputStream in = imageForOutput.getInputStream(); final byte[] content = new byte[(int) imageForOutput.getLength()]; in.read(content); out.write(content); in.close(); out.close(); return; } catch (final IOException e) { log.error(e); } } else { log.error("file not in db"); } } } final String titleChart = ChartEnumHelper.getByName(field).getTitle(); final String umChart = ChartEnumHelper.getByName(field).getUm(); final Query q = ds.createQuery(Meteolog.class); final Date dFrom = DateTimeUtil.getDate("yyyy-MM-dd hh:mm:ss", from); final Date dTo = DateTimeUtil.getDate("yyyy-MM-dd hh:mm:ss", to); q.disableValidation().filter("time >=", dFrom).filter("time <=", dTo); final List<Meteolog> meteoLogList = q.asList(); final TimeSeries series = new TimeSeries(umChart); for (Meteolog m : meteoLogList) { final Millisecond t = new Millisecond(m.getTime()); try { //violenza di una reflection final Method method = m.getClass().getMethod(ChartEnumHelper.getByName(field).getMethod()); final Number n = (Number) method.invoke(m); series.add(t, n); } catch (final NoSuchMethodException ex) { log.error(ex); } catch (final InvocationTargetException ex) { log.error(ex); } catch (final IllegalAccessException ex) { log.error(ex); } catch (final SecurityException ex) { log.error(ex); } } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); final JFreeChart chart = ChartFactory.createTimeSeriesChart(titleChart, "", umChart, dataset, false, false, false); final XYPlot plot = (XYPlot) chart.getPlot(); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy HH:mm")); axis.setVerticalTickLabels(true); if (field.toUpperCase().indexOf("PRESSURE") != -1) { plot.getRangeAxis().setRange(chartPressureMin, chartPressureMax); } final File f = File.createTempFile("mbmeteo", ".jpg"); ChartUtilities.saveChartAsJPEG(f, chart, dimx, dimy); try { if (cacheWriteEnable) { final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f); gfsFile.setFilename(f.getName()); gfsFile.save(); final Cache c = new Cache(); c.setServletName(this.getClass().getName()); c.setCacheKey(cacheKey); c.setGridId(gfsFile.getId().toString()); ds.save(c); } response.setContentType("image/jpeg"); response.setHeader("Content-Length", "" + f.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\""); final OutputStream out = response.getOutputStream(); final FileInputStream in = new FileInputStream(f.toString()); final int size = in.available(); final byte[] content = new byte[size]; in.read(content); out.write(content); in.close(); out.close(); } catch (final IOException e) { log.error(e); } finally { f.delete(); } }
From source file:org.codehaus.mojo.chronos.chart.HistoryChartGenerator.java
private void renderResponseChart(XYDataset dataset, String name, double max) throws IOException { String title = bundle.getString("chronos.label.responsetimes"); String xLabel = bundle.getString("chronos.label.responsetimes.historytime"); String yLabel = bundle.getString("chronos.label.responsetimes.responsetime"); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, true, true, false); /* Merged from Atlassion */ if (max > 0) { ChartUtil.setUpperBound(chart, max); }/*ww w.ja va2s . co m*/ ChartUtil.setupXYPlot(chart, new SimpleDateFormat()); renderer.renderChart(name, chart); }
From source file:com.vectorprint.report.jfree.ChartBuilder.java
private void prepareChart(Dataset data, CHARTTYPE type) throws VectorPrintException { switch (type) { case AREA://from w w w . j a v a 2 s .c om chart = ChartFactory.createAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case LINE: if (chart == null) { chart = ChartFactory.createLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case LINE3D: if (chart == null) { chart = ChartFactory.createLineChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR: if (chart == null) { chart = ChartFactory.createBarChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR3D: if (chart == null) { chart = ChartFactory.createBarChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof CategoryDataset) { CategoryDataset cd = (CategoryDataset) data; chart.getCategoryPlot().setDataset(cd); } else { throw new VectorPrintException("you should use CategoryDataset for this chart"); } break; case PIE: chart = ChartFactory.createPieChart(title, null, legend, tooltips, urls); case PIE3D: if (chart == null) { chart = ChartFactory.createPieChart3D(title, null, legend, tooltips, urls); } if (data instanceof PieDataset) { PieDataset pd = (PieDataset) data; PiePlot pp = (PiePlot) chart.getPlot(); pp.setDataset(pd); } else { throw new VectorPrintException("you should use PieDataset for this chart"); } break; case XYLINE: chart = ChartFactory.createXYLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case XYAREA: if (chart == null) { chart = ChartFactory.createXYAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof XYDataset) { XYDataset xy = (XYDataset) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use XYDataset for this chart"); } break; case TIME: chart = ChartFactory.createTimeSeriesChart(title, categoryLabel, valueLabel, null, legend, tooltips, urls); if (data instanceof TimeSeriesCollection) { TimeSeriesCollection xy = (TimeSeriesCollection) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use TimeSeriesCollection for this chart"); } break; default: throw new VectorPrintException("unsupported chart"); } chart.setAntiAlias(true); chart.setTextAntiAlias(true); }
From source file:serverrobot.DynamicGraph.java
public JFreeChart createChart(XYDataset dataset, String pos, double minRange, double maxRange) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(pos, "Time (ms)", "Displacement", dataset, true, true, false);/*w w w. jav a 2s .c o m*/ final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(232, 232, 232)); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.getRenderer().setSeriesPaint(0, Color.BLUE); plot.getRenderer().setSeriesPaint(1, Color.RED); ValueAxis axis = plot.getDomainAxis(); //axis.setAutoRange(true); axis.setFixedAutoRange(20000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(minRange, maxRange); chart.setBackgroundPaint(Color.white); return chart; }
From source file:com.view.TimeSeriesChartView.java
public JFreeChart getTimeSeriesChart(Excel theExcel, ReceivingControl theRC) { System.out.println(theRC.getNumberOfItem()); System.out.println(theRC.getNumberOfSite()); System.out.println(theRC.getNumberOfVendor()); System.out.println(theRC.getVendorInfo()); System.out.println(theRC.getSiteInfo()); System.out.println(theRC.getItemInfo()); // TimeSeries item1_xy_data = new TimeSeries("Item1"); // TimeSeries item2_xy_data = new TimeSeries("Item2"); // TimeSeries item3_xy_data = new TimeSeries("Item3"); ArrayList<Receiving> theReceiving = theExcel.getSheetReceiving(); // HashMap<Month, Integer> item1Map = new HashMap<>(); // HashMap<Month, Integer> item2Map = new HashMap<>(); // HashMap<Month, Integer> item3Map = new HashMap<>(); TimeSeries data[] = new TimeSeries[theRC.getNumberOfItem()]; HashMap<Month, Integer> itemMap[] = new HashMap[theRC.getNumberOfItem()]; for (int i = 0; i < theRC.getNumberOfItem(); i++) { String itemName = "item" + i; data[i] = new TimeSeries(itemName); itemMap[i] = new HashMap<>(); }//from www . j a va2 s. c om Calendar cal = Calendar.getInstance(); for (int i = 0; i < theReceiving.size(); i++) { cal.setTime(theReceiving.get(i).getDate()); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int quantity = theReceiving.get(i).getQuantity(); Month theMonth = new Month(month, year); int itemNum = theReceiving.get(i).getItem() - 1; itemMap[itemNum].put(theMonth, updateItemMap(itemMap[itemNum], theMonth, quantity)); // if (theReceiving[i].getItem() == 1) // { // item1Map.put(theMonth, updateItemMap(item1Map, theMonth, quantity)); // } // else if (theReceiving[i].getItem() == 2) // { // item2Map.put(theMonth, updateItemMap(item2Map, theMonth, quantity)); // } // else if (theReceiving[i].getItem() == 3) // { // item3Map.put(theMonth, updateItemMap(item3Map, theMonth, quantity)); // } } TimeSeriesCollection my_data_series = new TimeSeriesCollection(); for (int i = 0; i < theRC.getNumberOfItem(); i++) { for (Map.Entry<Month, Integer> entry : itemMap[i].entrySet()) { data[i].add(entry.getKey(), entry.getValue()); } my_data_series.addSeries(data[i]); } // add series using addSeries method // my_data_series.addSeries(item1_xy_data); // my_data_series.addSeries(item2_xy_data); // my_data_series.addSeries(item3_xy_data); JFreeChart chart = ChartFactory.createTimeSeriesChart("Receiving", "Month", "Quantity", my_data_series, true, true, false); chart.setBackgroundPaint(Color.YELLOW); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.GREEN); plot.setRangeGridlinePaint(Color.orange); plot.setAxisOffset(new RectangleInsets(50, 0, 20, 5)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MM.yyyy")); return chart; }
From source file:eu.cassandra.platform.gui.GUI.java
public JFreeChart createChart(String title, final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time", "Consumption (W)", dataset, false, true, true);//from www .j av a 2 s . co m DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1)); axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setDateFormatOverride(new SimpleDateFormat("dd")); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // BasicStroke basicStroke = new BasicStroke(1f); // renderer.setSeriesStroke(0, basicStroke); // chart.getXYPlot().setRenderer(renderer); chart.setAntiAlias(true); chart.setTextAntiAlias(true); return chart; }