Example usage for org.jfree.chart.axis CategoryAxis CategoryAxis

List of usage examples for org.jfree.chart.axis CategoryAxis CategoryAxis

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis CategoryAxis.

Prototype

public CategoryAxis(String label) 

Source Link

Document

Constructs a category axis, using default values where necessary.

Usage

From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.HierarchicalBarChart.java

private void buildFinalChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, int height,
        int width, String filename, Chart.Scale scaleMode, Chart.LegendFormat legendFormatMode, int alpha) {
    @SuppressWarnings("unchecked")
    Vector<Counter>[] vec = new Vector[this.timers.length];
    boolean exist;

    // create the dataset...
    for (int i = 0; i < this.timers.length; i++) {
        vec[i] = new Vector<Counter>();
        @SuppressWarnings("unchecked")
        Iterator<Element> it = this.timers[i].getDescendants();
        while (it.hasNext()) {
            try {
                Element elt = (Element) it.next();
                String name = elt.getAttributeValue("name");
                double value = Double.valueOf(elt.getAttributeValue("avg"));
                exist = false;//from w w  w. j  a va 2s. c  om
                for (int j = 0; j < vec[i].size(); j++) {
                    if (((Counter) vec[i].get(j)).getName().equals(name)) {
                        ((Counter) vec[i].get(j)).addValue(value);
                        exist = true;
                        break;
                    }
                }
                if (!exist) {
                    vec[i].add(new Counter(name, value));
                }
            } catch (ClassCastException e) {
                continue;
            }
        }
    }

    CategoryDataset dataset = null;
    try {
        dataset = DatasetUtilities.createCategoryDataset(toSeries(vec[0]), this.categories, toDataset(vec));
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        throw new IllegalArgumentException(
                "Benchmark names must have different names. Be sure that your filter contains correct timers names");
    }

    // create the chart...
    final CategoryAxis categoryAxis = new CategoryAxis(xAxisLabel);
    final ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new HierarchicalBarRenderer());

    plot.setOrientation(PlotOrientation.VERTICAL);
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.addSubtitle(new TextTitle(subTitle));

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    final HierarchicalBarRenderer renderer = (HierarchicalBarRenderer) plot.getRenderer();

    renderer.setItemMargin(0.01);
    renderer.setDatasetTree(this.timers);
    renderer.setSeries(toSeries(vec[0]));
    renderer.setAlpha(alpha);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(HierarchicalBarChart.CATEGORY_MARGIN);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    try {
        if ((filename == null) || "".equals(filename)) {
            throw new RuntimeException(
                    "The output filename for the HierarchicalBarChart cannot be null or empty !");
        }

        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 chart image to file");
        e.printStackTrace();
    }
}

From source file:org.ow2.clif.jenkins.ClifProjectAction.java

private JFreeChart createActionGraph(ClifGraphParam params) {
    DefaultStatisticalCategoryDataset timeDS = new DefaultStatisticalCategoryDataset();
    DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> minmaxDS = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>();

    List<AbstractBuild> builds = new ArrayList<AbstractBuild>(getProject().getBuilds());
    Collections.sort(builds);/*from w w  w  .  ja va  2  s .  c o m*/
    for (Run<?, ?> currentBuild : builds) {
        Result buildResult = currentBuild.getResult();
        if (buildResult != null && buildResult.isBetterOrEqualTo(Result.SUCCESS)) {
            ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(currentBuild);
            ClifBuildAction clifBuildAction = currentBuild.getAction(ClifBuildAction.class);
            if (clifBuildAction == null) {
                continue;
            }
            ClifReport clifReport = clifBuildAction.getReport();
            if (clifReport == null) {
                continue;
            }
            TestPlan tp = clifReport.getTestplan(params.getTestPlan());
            if (tp == null) {
                continue;
            }
            if (tp.getAggregatedMeasures() != null) {
                Measure m = tp.getAggregatedMeasure(params.getLabel());
                if (m == null) {
                    continue;
                }
                timeDS.add(m.getAverage(), m.getStdDev(), Messages.ProjectAction_Mean(), label);
                minmaxDS.add(m.getMax(), Messages.ProjectAction_Max(), label);
                minmaxDS.add(m.getMin(), Messages.ProjectAction_Min(), label);
            }
        }
    }

    final CategoryAxis xAxis = new CategoryAxis(Messages.ProjectAction_BuildAxis());
    xAxis.setLowerMargin(0.01);
    xAxis.setUpperMargin(0.01);
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    xAxis.setMaximumCategoryLabelLines(3);

    final ValueAxis timeAxis = new NumberAxis(Messages.ProjectAction_TimeAxis());
    timeAxis.setUpperMargin(0.1);
    // final ValueAxis minmaxTimeAxis = new NumberAxis("Time (ms)");
    final BarRenderer timeRenderer = new StatisticalBarRenderer();
    timeRenderer.setSeriesPaint(2, ColorPalette.RED);
    timeRenderer.setSeriesPaint(1, ColorPalette.YELLOW);
    timeRenderer.setSeriesPaint(0, ColorPalette.BLUE);
    timeRenderer.setItemMargin(0.0);

    final CategoryPlot plot = new CategoryPlot(timeDS, xAxis, timeAxis, timeRenderer);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    final CategoryItemRenderer minmaxRenderer = new LineAndShapeRenderer();
    // plot.setRangeAxis(1, timeAxis);
    plot.setDataset(1, minmaxDS.build());
    plot.mapDatasetToRangeAxis(1, 0);
    plot.setRenderer(1, minmaxRenderer);

    JFreeChart chart = new JFreeChart(params.getLabel(), plot);
    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:genj.chart.Chart.java

/**
 * Constructor for a chart with indexed series and categories where
 * each category groups the values of all series.
 * Example:/*from w w  w . ja  va2 s . co  m*/
 * <pre>
 *   X     Y          Z
 *   |Y   X|Z   Y     |
 *   ||Z  |||  X|Z  XY|
 *   Jan  Feb  Mar  Apr
 * </pre>
 * or
 * <pre>
 *         X
 *    X    X
 *    X    Y         X
 *    X    Y    X    Y
 *    Y    Y    Y    Z
 *    Y    Z    Y    Z
 *    Z    Z    Z    Z
 *   Jan  Feb  Mar  Apr
 * </pre>
 * @param title the title of the chart
 * @param labelCatAxis a label for category-axis
 * @param series one or more indexed series to show
 * @param categories the categories to show 
 * @param format a number format to use for y-values
 * @param isStacked whether to stack series per categories instead of placing them side by side
 * @param isVertical whether to show the chart vertical instead of horizontal
 */
public Chart(String title, String labelCatAxis, IndexedSeries[] series, String[] categories,
        NumberFormat format, boolean isStacked, boolean isVertical) {

    // wrap into JFreeChart
    CategoryAxis categoryAxis = new CategoryAxis(labelCatAxis);
    NumberAxis valueAxis = new NumberAxis();
    valueAxis.setNumberFormatOverride(format);

    BarRenderer renderer;
    if (isStacked) {
        renderer = new StackedBarRenderer();
    } else {
        renderer = new BarRenderer();
    }

    // TODO Charts - colors are hardcoded atm
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setSeriesPaint(1, Color.RED);

    // prepare plot
    CategoryPlot plot = new CategoryPlot(IndexedSeries.asCategoryDataset(series, categories), categoryAxis,
            valueAxis, renderer);
    plot.setOrientation(!isVertical ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL);

    // init
    init(title, plot, true);

    // done
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.ProfilesComparisonReportChartCanvas.java

private void createChart() {

    // create dataset
    theDataset = createDataset();//from  w w w.j a  v  a2 s . c om

    // create axis
    CategoryAxis categoryAxis = new CategoryAxis("");
    categoryAxis.setCategoryLabelPositions(org.jfree.chart.axis.CategoryLabelPositions.UP_45);
    ValueAxis valueAxis = new NumberAxis("Normalized Intensities");

    // create renderer
    CategoryItemRenderer renderer = null;
    if (theOptions.REPRESENTATION == theOptions.BARS)
        renderer = new org.jfree.chart.renderer.category.BarRenderer();
    else if (theOptions.REPRESENTATION == theOptions.ERRORBARS)
        renderer = new org.jfree.chart.renderer.category.StatisticalBarRenderer();
    else if (theOptions.REPRESENTATION == theOptions.DISTRIBUTIONS)
        renderer = new org.jfree.chart.renderer.category.ScatterRenderer();

    ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
    renderer.setBasePositiveItemLabelPosition(position1);
    ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
    renderer.setBaseNegativeItemLabelPosition(position2);

    // create plot
    thePlot = new CategoryPlot(theDataset, categoryAxis, valueAxis, renderer);
    thePlot.setOrientation(org.jfree.chart.plot.PlotOrientation.VERTICAL);

    // add mean values 
    if (theOptions.REPRESENTATION == theOptions.DISTRIBUTIONS) {
        thePlot.setDataset(1, createMeansDataset());
        thePlot.mapDatasetToRangeAxis(1, 0);

        CategoryItemRenderer lr = new org.jfree.chart.renderer.category.LevelRenderer();
        lr.setPaint(Color.black);
        thePlot.setRenderer(1, lr);
    }

    // create chart
    theChart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thePlot, true);
    theChart.setBackgroundPaint(Color.white);
    theChart.setBorderVisible(false);

}

From source file:org.jfree.chart.demo.CombinedCategoryPlotDemo1.java

/**
 * Creates a chart./* w  ww  . j  av  a  2 s .c  o  m*/
 *
 * @return A chart.
 */
private JFreeChart createChart() {

    final CategoryDataset dataset1 = createDataset1();
    final NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    final CategoryDataset dataset2 = createDataset2();
    final NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    final CategoryAxis domainAxis = new CategoryAxis("Category");
    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    final JFreeChart result = new JFreeChart("Combined Domain Category Plot Demo",
            new Font("SansSerif", Font.BOLD, 12), plot, true);
    //      result.getLegend().setAnchor(Legend.SOUTH);
    return result;

}

From source file:playground.johannes.snowball.Histogram.java

public void plot(String filename, String title) throws IOException {
    fillBins();/*from ww w  . j  a va 2 s  .  c o m*/
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    double min, max, width;
    //      int size;

    if (bounds != null) {
        min = bounds[0];
        max = bounds[1];
    } else {
        double minmax[] = getMinMax();
        min = minmax[0];
        max = minmax[1];
    }
    if (binWidth > 0) {
        //         size = (int)Math.ceil((max - min)/(double)binWidth);
        width = binWidth;
    } else {
        //         size = bincount;
        width = (max - min) / (double) bincount;
    }

    int cnt = bins.size();
    for (int i = 0; i < cnt; i++) {
        wave.add(i * width + min, bins.get(i));
    }

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("x");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("y"));
    ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768);
}

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateBWLog2IntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session,
        PrintWriter pw, boolean isCoinPlot) {
    String bwFilename = "";

    //PlotSize ps = PlotSize.MEDIUM;

    JFreeChart bwChart = null;//from   ww w  .j  a  v  a 2 s  .c  om
    try {
        //IMAGE Size Control

        CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        NumberAxis yAxis = new NumberAxis(yAxisLabel);
        yAxis.setAutoRangeIncludesZero(true);
        BoxAndWhiskerCoinPlotRenderer bwRenderer = null;
        CategoryPlot bwPlot = null;

        if (isCoinPlot) {
            Map<String, List<Double>> groupMap = rawDataMap.get(reporterName);
            DefaultBoxAndWhiskerCategoryDataset smallBwdataset = new DefaultBoxAndWhiskerCategoryDataset();
            int row = 0;
            int column = 0;
            HashMap<String, List> caIntegatorCoinList = new HashMap<String, List>();
            for (String group : groupList) {
                smallBwdataset.add(groupMap.get(group), reporterName, group);
                caIntegatorCoinList.put(row + "_" + column++, groupMap.get(group));
            }
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer(caIntegatorCoinList);
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setDisplayCoinCloud(true);
            bwRenderer.setDisplayMean(false);
            bwRenderer.setFillBox(false);
            bwRenderer.setPlotColor(null);
            bwPlot = new CategoryPlot(smallBwdataset, xAxis, yAxis, bwRenderer);

            if (groupList.size() < 6)
                imgW = 200;

        } else {
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer();
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
                public String generateToolTip(CategoryDataset dataset, int series, int item) {
                    String tt = "";
                    NumberFormat formatter = new DecimalFormat(".####");
                    String key = "";
                    //String s = formatter.format(-1234.567);  // -001235
                    if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                        DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                        try {
                            String med = formatter.format(ds.getMedianValue(series, item));
                            tt += "Median: " + med + "<br/>";
                            tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                            tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                            tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                            tt += "Max: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "Min: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                            key = ds.getRowKeys().get(series).toString();
                        } catch (Exception e) {
                        }
                    }
                    String returnString = "onclick=\"popCoin('" + geneSymbol + "','" + key + "');\" | ";

                    return returnString + tt;
                }
            });
            bwRenderer.setFillBox(false);
            bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer);
        }

        bwChart = new JFreeChart(bwPlot);

        bwChart.setBackgroundPaint(java.awt.Color.white);
        LegendTitle title = bwChart.getLegend();
        LegendItemSource[] sources = title.getSources();

        legendItemCollection = sources[0].getLegendItems();
        bwChart.removeLegend();

        // Write the chart image to the temporary directory
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

        // BW
        if (bwChart != null) {
            //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue();
            bwFilename = ServletUtilities.saveChartAsPNG(bwChart, imgW, 400, info, session);
            CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator();
            ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer
            ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator());
            info.clear(); // lose the first one
            info = new ChartRenderingInfo(new StandardEntityCollection());
        }
        //END  BW

        pw.flush();

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    // return filename;
    //charts.put("errorBars", log2Filename);
    //charts.put("noErrorBars", rawFilename);
    //charts.put("bwFilename", bwFilename);
    //charts.put("legend", legendHtml);
    //charts.put("size", ps.toString());

    return bwFilename;
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaActivityWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//*from   w  ww .ja  va2  s . c  om*/
private JFreeChart getGraphic(int[] activities, int[] activitiesParticipatingAtHome,
        int[] activitiesParticipatingNotAtHome, int[] activitiesNotParticipatingAtHome,
        int[] activitiesNotParticipatingNotAtHome) {

    final XYSeriesCollection xyData = new XYSeriesCollection();
    XYSeries dataSerie;

    dataSerie = new XYSeries("total activity performing agents in evacuated area", false, true);
    for (int i = 0; i < activities.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activities[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("participating agents performing a home activity in evacuated area", false, true);
    for (int i = 0; i < activitiesParticipatingAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesParticipatingAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("participating agents performing an other activity in evacuated area", false,
            true);
    for (int i = 0; i < activitiesParticipatingNotAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesParticipatingNotAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("not participating agents performing a home activity in evacuated area", false,
            true);
    for (int i = 0; i < activitiesNotParticipatingAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesNotParticipatingAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("not participating agents performing an other activity in evacuated area", false,
            true);
    for (int i = 0; i < activitiesNotParticipatingNotAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesNotParticipatingNotAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "activity performing agents in evacuated area, it." + this.iteration, "time", "# agents", 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"));
    return chart;
}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

public void updateChartData() {
    this.printable = false;

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

    final CategoryAxis xAxis = new CategoryAxis(this.xAxisTitle);
    final NumberAxis yAxis = new NumberAxis(this.yAxisTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(this.chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot,
            true);/* w ww  . ja  v  a2 s .c o m*/
    this.plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));

    setContentPane(this.chartPanel);

    this.pack();
    this.setVisible(true);
    this.printable = true;

}

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,//w  w w  .  ja v  a 2 s  . 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();
    }
}