23 package org.matsim.analysis;
25 import org.jfree.chart.ChartFactory;
26 import org.jfree.chart.ChartUtils;
27 import org.jfree.chart.JFreeChart;
28 import org.jfree.chart.axis.CategoryAxis;
29 import org.jfree.chart.axis.NumberAxis;
30 import org.jfree.chart.plot.PlotOrientation;
31 import org.jfree.chart.plot.XYPlot;
32 import org.jfree.data.xy.XYSeries;
33 import org.jfree.data.xy.XYSeriesCollection;
37 import java.io.IOException;
38 import java.io.UncheckedIOException;
41 static JFreeChart getGraphic(
final LegHistogram.
DataFrame dataFrame,
final String mode,
int iteration) {
42 final XYSeriesCollection xyData =
new XYSeriesCollection();
43 final XYSeries departuresSerie =
new XYSeries(
"departures",
false,
true);
44 final XYSeries arrivalsSerie =
new XYSeries(
"arrivals",
false,
true);
45 final XYSeries onRouteSerie =
new XYSeries(
"en route",
false,
true);
47 for (
int i = 0; i < dataFrame.countsDep.length; i++) {
48 onRoute = onRoute + dataFrame.countsDep[i] - dataFrame.countsArr[i] - dataFrame.countsStuck[i];
49 double hour = i*dataFrame.binSize / 60.0 / 60.0;
50 departuresSerie.add(hour, dataFrame.countsDep[i]);
51 arrivalsSerie.add(hour, dataFrame.countsArr[i]);
52 onRouteSerie.add(hour, onRoute);
55 xyData.addSeries(departuresSerie);
56 xyData.addSeries(arrivalsSerie);
57 xyData.addSeries(onRouteSerie);
59 final JFreeChart chart = ChartFactory.createXYStepChart(
60 "Leg Histogram, " + mode +
", it." + iteration,
63 PlotOrientation.VERTICAL,
69 XYPlot plot = chart.getXYPlot();
71 final CategoryAxis axis1 =
new CategoryAxis(
"hour");
72 axis1.setTickLabelFont(
new Font(
"SansSerif", Font.PLAIN, 7));
73 plot.setDomainAxis(
new NumberAxis(
"time"));
75 plot.getRenderer().setSeriesStroke(0,
new BasicStroke(2.0f));
76 plot.getRenderer().setSeriesStroke(1,
new BasicStroke(2.0f));
77 plot.getRenderer().setSeriesStroke(2,
new BasicStroke(2.0f));
78 plot.setBackgroundPaint(Color.white);
79 plot.setRangeGridlinePaint(Color.gray);
80 plot.setDomainGridlinePaint(Color.gray);
95 ChartUtils.saveChartAsPNG(
new File(filename), getGraphic(legHistogram.getAllModesData(),
"all", legHistogram.getIteration()), 1024, 768);
96 }
catch (IOException e) {
97 throw new UncheckedIOException(e);
113 ChartUtils.saveChartAsPNG(
new File(filename), getGraphic(legHistogram.getDataForMode(legMode), legMode, legHistogram.getIteration()), 1024, 768);
114 }
catch (IOException e) {
115 throw new UncheckedIOException(e);
static void writeGraphic(LegHistogram legHistogram, final String filename, final String legMode)
static void writeGraphic(LegHistogram legHistogram, final String filename)