List of usage examples for org.jfree.chart ChartUtilities saveChartAsPNG
public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height) throws IOException
From source file:playground.christoph.icem2011.LogLinkTravelTime.java
private void createChart(Link link, String file) { // String s = data.get(linkId).toString(); // String[] travelTimes = s.split("\n"); List<Double> etts = data.get(link.getId()); final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries expectedTravelTimes = new XYSeries("expected travel times", false, true); final XYSeries measuredTravelTimes = new XYSeries("measured travel times", false, true); for (int i = 0; i < times.size(); i++) { double time = times.get(i); if (time > graphCutOffTime) break; // do not display values > 30h in the graph double hour = Double.valueOf(time) / 3600.0; expectedTravelTimes.add(hour, Double.valueOf(etts.get(i))); measuredTravelTimes.add(hour,/* ww w . ja va 2s . co m*/ Double.valueOf(measuredTravelTime.getLinkTravelTime(link, time, null, null))); } xyData.addSeries(expectedTravelTimes); xyData.addSeries(measuredTravelTimes); // final JFreeChart chart = ChartFactory.createXYStepChart( final JFreeChart chart = ChartFactory.createXYLineChart( "Compare expected and measured travel times for link " + link.getId().toString(), "time", "travel time", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("time")); try { ChartUtilities.saveChartAsPNG(new File(file), chart, 1024, 768); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.Line2dChart.java
/** * * @param title//from w ww . j a v a 2 s.c om * @param subTitle * @param fileName * @param domainAxis * @param rangeAxis * @param width * @param height */ private void buildFinalChart(String title, String subTitle, String fileName, String domainAxis, String rangeAxis, int width, int height) { CategoryDataset dataset = this.createDataset(); JFreeChart chart = ChartFactory.createLineChart(title, domainAxis, // domain // axis // label rangeAxis, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.addSubtitle(new TextTitle(subTitle)); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot c = chart.getCategoryPlot(); c.setRenderer(renderer); c.setRangeGridlinesVisible(true); try { ChartUtilities.saveChartAsPNG(XMLHelper.createFileWithDirs(fileName + ".png"), chart, width, height); Utilities.saveChartAsSVG(chart, new Rectangle(width, height), XMLHelper.createFileWithDirs(fileName + ".svg")); } catch (java.io.IOException e) { System.err.println("Error writing image to file"); e.printStackTrace(); } }
From source file:com.jolbox.benchmark.BenchmarkMain.java
/** * @param title // w w w . ja v a 2 s . com * @param filename * @param results */ private static void plotBarGraph(String title, String filename, long[] results) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ConnectionPoolType poolType : ConnectionPoolType.values()) { dataset.setValue(results[poolType.ordinal()], "ms", poolType); } JFreeChart chart = ChartFactory.createBarChart(title, "Connection Pool", "Time (ms)", dataset, PlotOrientation.VERTICAL, false, true, false); try { String fname = System.getProperty("java.io.tmpdir") + File.separator + filename; ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768); System.out.println("******* Saved chart to: " + fname); } catch (IOException e) { e.printStackTrace(); System.err.println("Problem occurred creating chart."); } }
From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java
/** * Generating the frontpage graph that shows the total amount of different wf types */// w w w .jav a2s . c o m protected void generateFrontpageGraph() { // count the number of workflows of each type: List names = wfman.getWorkflowTemplateNames(); DefaultPieDataset dataset = new DefaultPieDataset(); int wfcount = 0; for (Iterator it = names.iterator(); it.hasNext();) { String template = (String) it.next(); PropertyFilter templatefilter = new PropertyFilter(); templatefilter.addWfTemplate(template); int count = wfman.getWorkflowIds(templatefilter, null).size(); if (count > 0) { dataset.setValue(template, new Double(count)); } wfcount += count; } // only generate graph if workflows exist if (wfcount > 0) { JFreeChart chart = ChartFactory.createPieChart3D("Workflows inside SWAMP", dataset, false, false, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.6f); File image = new File(statPath + fs + "workflows.png"); if (image.exists()) image.delete(); try { ChartUtilities.saveChartAsPNG(image, chart, 500, 350); } catch (java.io.IOException exc) { Logger.ERROR("Error writing image to file: " + exc.getMessage()); } } }
From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java
public static void plotLineChart(Map<String, List<Double>> series, String filename, String title, String labelX, String labelY) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); for (String label : series.keySet()) { XYSeries data = new XYSeries(label); int t = 0; for (Double d : series.get(label)) { data.add(t, d);/* w ww .j a va 2s .c om*/ t++; } dataset.addSeries(data); } JFreeChart chart = ChartFactory.createXYLineChart(title, labelX, labelY, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768); }
From source file:com.jolbox.benchmark.BenchmarkLaunch.java
/** * @param title // w ww .ja v a 2 s .c o m * @param filename * @param results * @throws IOException */ private static void plotBarGraph(String title, String filename, long[] results) throws IOException { String fname = System.getProperty("java.io.tmpdir") + File.separator + filename; PrintWriter out = new PrintWriter(new FileWriter(fname + ".txt")); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ConnectionPoolType poolType : ConnectionPoolType.values()) { dataset.setValue(results[poolType.ordinal()], "ms", poolType); out.println(results[poolType.ordinal()] + "," + poolType); } out.close(); JFreeChart chart = ChartFactory.createBarChart(title, "Connection Pool", "Time (ms)", dataset, PlotOrientation.VERTICAL, false, true, false); try { ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768); System.out.println("******* Saved chart to: " + fname); } catch (IOException e) { e.printStackTrace(); System.err.println("Problem occurred creating chart."); } }
From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java
public void writeGraphic(final String filename, String[] legModes, int[][] data) { try {//from w w w . j av a2s . c om ChartUtilities.saveChartAsPNG(new File(filename), getGraphic(legModes, data), 1024, 768); } catch (IOException e) { e.printStackTrace(); } }
From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java
/** * Save a chart to a file.//from ww w .j a v a 2s. com * * @param chart the chart to save * @param filename the filename to save to * @param width width of the saved image * @param height height of the saved image * @throws Exception if the chart can't be saved for some reason */ @Override public void saveChartToFile(JPanel chart, String filename, int width, int height) throws Exception { if (!(chart instanceof ChartPanel)) { throw new Exception("Chart is not a JFreeChart!"); } if (filename.toLowerCase().lastIndexOf(".png") < 0) { filename = filename + ".png"; } ChartUtilities.saveChartAsPNG(new File(filename), ((ChartPanel) chart).getChart(), width, height); }
From source file:canreg.client.analysis.Tools.java
static String writeJChartToFile(JFreeChart chart, File file, FileTypes fileType) throws IOException, DocumentException { String fileName = file.getPath(); switch (fileType) { case svg://from w w w . j ava 2 s.c o m Tools.exportChartAsSVG(chart, new Rectangle(1000, 1000), file); break; case pdf: Tools.exportChartAsPDF(chart, new Rectangle(500, 400), file); break; case jchart: break; case csv: Tools.exportChartAsCSV(chart, file); break; default: ChartUtilities.saveChartAsPNG(file, chart, 1000, 1000); break; } return fileName; }
From source file:org.remus.marketplace.scheduling.GenerateStatisticsJob.java
private void createDownloadStatistics(Integer id, File folder, Node node, Calendar instance) { Map<Date, Integer> map = new HashMap<Date, Integer>(); for (int i = 0, n = month; i < n; i++) { Calendar instance2 = Calendar.getInstance(); instance2.setTime(new Date()); instance2.add(Calendar.MONTH, i * -1); map.put(instance2.getTime(), 0); }// w w w . ja v a 2s .c o m AdvancedCriteria criteria = new AdvancedCriteria() .addRestriction(Restrictions.between(Download.TIME, instance.getTime(), new Date())) .addRestriction(Restrictions.eq(Download.NODE, node)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.count(Download.NODE)); projectionList .add(Projections.sqlGroupProjection("month({alias}.time) as month, year({alias}.time) as year", "month({alias}.time), year({alias}.time)", new String[] { "month", "year" }, new Type[] { Hibernate.INTEGER, Hibernate.INTEGER })); criteria.setProjection(projectionList); List<Object> query = downloadDao.query(criteria); for (Object object : query) { Object[] data = (Object[]) object; Integer count = (Integer) data[0]; Integer month = (Integer) data[1]; Integer year = (Integer) data[2]; Set<Date> keySet = map.keySet(); for (Date date : keySet) { Calendar instance2 = Calendar.getInstance(); instance2.setTime(date); if (instance2.get(Calendar.YEAR) == year && instance2.get(Calendar.MONTH) == month - 1) { map.put(date, count); } } } DefaultCategoryDataset data = new DefaultCategoryDataset(); List<Date> keySet = new ArrayList<Date>(map.keySet()); Collections.sort(keySet, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); for (Date date : keySet) { Integer integer = map.get(date); Calendar instance2 = Calendar.getInstance(); instance2.setTime(date); int year = instance2.get(Calendar.YEAR); int month = instance2.get(Calendar.MONTH) + 1; data.addValue(integer, "Column1", month + "-" + year); } JFreeChart createBarChart = ChartFactory.createBarChart("Downloads", "Month", "", data, PlotOrientation.VERTICAL, false, false, false); File file = new File(folder, "download_" + id + ".png"); if (file.exists()) { file.delete(); } try { ChartUtilities.saveChartAsPNG(file, createBarChart, 500, 300); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }