List of usage examples for org.jfree.chart ChartUtilities saveChartAsPNG
public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info, boolean encodeAlpha, int compression) throws IOException
From source file:org.matsim.contrib.parking.parkingchoice.PC2.analysis.ParkingGroupOccupancies.java
public void savePlot(String fileName) { final JFreeChart chart = LineChart.createChart(xySeriesCollection, "Parking Group Occupancies"); try {// w ww .j a v a2 s . c om ChartUtilities.saveChartAsPNG(new File(fileName), chart, 800, 600, null, true, 9); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:playground.yu.utils.charts.DoubleBarChart.java
/** * @param args// ww w . ja va2 s . c o m */ public static void run0(String[] args) { String chartFilename = "../matsimTests/charts/barChart.png"; BarChart chartA = new BarChart("", "", "Wegdistanz - MZ05", new String[] { "Arbeit (work)", "Rueckkehr nach Hause bzw. auswaertige Unterkunft (home)", "Freizeit (leisure)", "Einkauf (shopping)", "Ausbildung/Schule (education)", "Andere", "Geschaeftliche Taetigkeit und Dienstfahrt", "Service- und Begleitwege", "total" }); chartA.addSeries("MIV (car)", new double[] { 9.04, 33.90, 12.20, 7.15, 6.83, 6.28, 14.39, 4.48, 10.16 }); chartA.addSeries("OeV (pt)", new double[] { 10.86, 36.80, 15.04, 5.67, 10.06, 54.11, 33.04, 9.02, 12.19 }); chartA.addSeries("LV (walk)", new double[] { 1.19, 0.24, 0.81, 0.70, 2.17, 0.57, 1.93, 0.75, 1.04 }); chartA.addSeries("Andere (others)", new double[] { 18.16, 22.23, 10.78, 5.19, 0.84, 12.97, 44.90, 3.7, 11.76 }); CategoryPlot subplotA = chartA.getChart().getCategoryPlot(); BarChart chartB = new BarChart("", "", "Wegdistanz - Matsim-run698", new String[] { "Arbeit (work)", "Rueckkehr nach Hause bzw. auswaertige Unterkunft (home)", "Freizeit (leisure)", "Einkauf (shopping)", "Ausbildung/Schule (education)", "Andere", "Geschaeftliche Taetigkeit und Dienstfahrt", "Service- und Begleitwege", "total" }); chartB.addSeries("MIV (car)", new double[] { 10.71, 7.79, 6.28, 5.77, 6.65, 0, 0, 0, 8.05 }); chartB.addSeries("OeV (pt)", new double[] { 6.37, 6.10, 4.10, 4.10, 4.64, 0, 0, 0, 5.44 }); chartB.addSeries("LV (walk)", new double[] { 0.88, 0.85, 0.75, 0.75, 0.81, 0, 0, 0, 0.81 }); chartB.addSeries("Andere (others)", new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }); CategoryPlot subplotB = chartB.getChart().getCategoryPlot(); final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot( new CategoryAxis("Verkehrszwecke/ travel destinations")); plot.add(subplotA, 1); plot.add(subplotB, 1); final JFreeChart result = new JFreeChart("MZ05 vs MATSim - mittlere Wegdistanz", JFreeChart.DEFAULT_TITLE_FONT, plot, true); try { ChartUtilities.saveChartAsPNG(new File(chartFilename), result, 1024, 768, null, true, 9); } catch (IOException e) { e.printStackTrace(); } // chartA.saveAsPng(chartFilename, 800, 600); }
From source file:org.matsim.pt.analysis.RouteTimeDiagram.java
public void createGraph(final String filename, final TransitRoute route) { HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>(); int idx = 0;// w w w .j a v a2 s .com for (TransitRouteStop stop : route.getStops()) { stopIndex.put(stop.getStopFacility().getId(), idx); idx++; } HashSet<Id> vehicles = new HashSet<Id>(); for (Departure dep : route.getDepartures().values()) { vehicles.add(dep.getVehicleId()); } XYSeriesCollection dataset = new XYSeriesCollection(); int numSeries = 0; double earliestTime = Double.POSITIVE_INFINITY; double latestTime = Double.NEGATIVE_INFINITY; for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) { if (vehicles.contains(entry.getKey())) { XYSeries series = new XYSeries("t", false, true); for (Tuple<Id, Double> pos : entry.getValue()) { Integer stopIdx = stopIndex.get(pos.getFirst()); if (stopIdx != null) { double time = pos.getSecond().doubleValue(); series.add(stopIdx.intValue(), time); if (time < earliestTime) { earliestTime = time; } if (time > latestTime) { latestTime = time; } } } dataset.addSeries(series); numSeries++; } } JFreeChart c = ChartFactory.createXYLineChart("Route-Time Diagram, Route = " + route.getId(), "stops", "time", dataset, PlotOrientation.VERTICAL, false, // legend? false, // tooltips? false // URLs? ); c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f)); XYPlot p = (XYPlot) c.getPlot(); p.getRangeAxis().setInverted(true); p.getRangeAxis().setRange(earliestTime, latestTime); XYItemRenderer renderer = p.getRenderer(); for (int i = 0; i < numSeries; i++) { renderer.setSeriesPaint(i, Color.black); } try { ChartUtilities.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9); } catch (IOException e) { e.printStackTrace(); } }