Example usage for org.jfree.chart.title TextTitle TextTitle

List of usage examples for org.jfree.chart.title TextTitle TextTitle

Introduction

In this page you can find the example usage for org.jfree.chart.title TextTitle TextTitle.

Prototype

public TextTitle(String text) 

Source Link

Document

Creates a new title, using default attributes where necessary.

Usage

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

/**
 * Creates a sample chart.//from   w  ww. j  a v a2s . com
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart("Performance: JFreeSVG vs Batik", null /* x-axis label*/,
            "Milliseconds" /* y-axis label */, dataset);
    chart.addSubtitle(
            new TextTitle("Time to generate 1000 charts in SVG " + "format (lower bars = better performance)"));
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    chart.getLegend().setFrame(BlockBorder.NONE);
    return chart;
}

From source file:unalcol.termites.boxplots.ECALAgentsRight.java

/**
 * Creates a new demo./*from  w ww .  ja  va  2  s  .  co  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public ECALAgentsRight(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //        final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");

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

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Agents Right " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("ECALright" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:unalcol.termites.boxplots.RoundNumber2.java

/**
 * Creates a new demo./*w ww  .j  av a 2 s. c  o  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumber2(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //        final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");

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

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("roundnumber2" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 300, 250, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumber2.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumber2.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:unalcol.termites.boxplots.ECALRoundNumber.java

/**
 * Creates a new demo.//  w  w w . j a  v a2  s  . com
 *
 * @param title the frame title.
 * @param pf
 */
public ECALRoundNumber(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //        final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");

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

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("ECALround" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ECALRoundNumber.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ECALRoundNumber.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:unalcol.termites.boxplots.InformationCollected2.java

/**
 * Creates a new demo.//from   ww  w. j  av  a2s .c o m
 *
 * @param title the frame title.
 * @param pf
 */
public InformationCollected2(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

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

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("informationcollected2" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:unalcol.termites.boxplots.RoundNumber1.java

/**
 * Creates a new demo./*from w  w  w.j av  a  2 s.co  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumber1(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18),
            plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("roundnumber1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:unalcol.termites.boxplots.HybridInformationCollected.java

/**
 * Creates a new demo./*  w  w  w .  ja v a  2s .  c o  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public HybridInformationCollected(final String title, ArrayList<Double> pf) {
    super(title);
    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);
    final CategoryAxis xAxis = new CategoryAxis("");
    final NumberAxis yAxis = new NumberAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 12);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Total of Information Collected " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 12), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1300, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);
    FileOutputStream output;
    try {
        output = new FileOutputStream("totalInformationCollected" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1300, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HybridInformationCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HybridInformationCollected.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.posterita.core.BarChart.java

public JFreeChart createChart() throws OperationException {
    if (dataset == null) {
        throw new OperationException("Cannot create Bar chart: cause -> dataset empty!");
    }/* w w w  .j  a v a2s. c  om*/

    switch (type) {
    case BARCHART_FLAT:
        chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, orientation, showLegend,
                showTooltip, true);
        break;

    case BARCHART_3D:
        chart = ChartFactory.createBarChart3D(title, xLabel, yLabel, dataset, orientation, showLegend,
                showTooltip, true);
        break;

    default:
        throw new OperationException(
                "Invalid barchart type! Can only be BarChart.BARCHART_FLAT or BarChart.BARCHART_3D");
    }

    //setting subtitle
    if (subtitle != null) {
        TextTitle title = new TextTitle(subtitle);
        chart.addSubtitle(title);
    }

    CategoryPlot plot = chart.getCategoryPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();

    //setting tickUnits
    if (integerTickUnits)
        axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer barRender = (BarRenderer) plot.getRenderer();
    barRender.setMaximumBarWidth(maximumBarWidth);

    //displaying labels
    if (showLabels) {
        CategoryItemRenderer itemRender = plot.getRenderer();
        itemRender.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        itemRender.setItemLabelsVisible(true);
    }

    return chart;
}

From source file:cz.muni.fi.nbs.utils.Helpers.java

private static void exportToPNG(Map<String, Collection<Result>> results) {

    for (Entry<String, Collection<Result>> entry : results.entrySet()) {
        double number = 0;
        String key = entry.getKey();
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        Iterator<Result> resultsIterator = results.get(key).iterator();
        while (resultsIterator.hasNext()) {
            Result r = resultsIterator.next();
            dataset.addValue(r.getScore(), r.getLabel(), "");
            number += 0.8;/*from   w ww . j a  va 2s.co  m*/
        }
        double width = number > 1 ? number * 200 : 300;
        String unit = entry.getValue().iterator().next().getScoreUnit();
        String[] splitKey = key.split("_");

        JFreeChart chart = ChartFactory.createBarChart3D(splitKey[0], null, unit, dataset);

        int len = splitKey.length / 2;
        for (int i = 0; i < len; i++) {
            String subtitle = splitKey[i * 2 + 1] + ":" + splitKey[i * 2 + 2];
            TextTitle title = new TextTitle(subtitle);
            Font oldFont = title.getFont();
            int fontSize = (int) Math.round(oldFont.getSize() * 1.2);
            int fontStyle = oldFont.getStyle();
            String fontName = oldFont.getName();

            title.setFont(new Font(fontName, fontStyle, fontSize));
            chart.addSubtitle(title);
        }
        try {
            ChartUtilities.saveChartAsPNG(new File(resultsDir + "/charts/" + key + "Chart.png"), chart,
                    (int) Math.round(width), 800);
        } catch (IOException ex) {
            Logger.getLogger(Helpers.class.getName()).log(Level.SEVERE,
                    "Could not export chart to PNG file for " + key, ex);
        }
    }
}

From source file:unalcol.termites.boxplots.RoundNumberGlobal.java

/**
 * Creates a new demo.//from  w  w w .  j  a va 2s  . c om
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumberGlobal(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18),
            plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("roundGlobalNumber" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    }

}