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.experimental.chart.annotations.junit.XYTitleAnnotationTests.java

/**
 * Confirm that the equals method can distinguish all the required fields.
 *///from  w  ww. ja va2s  . c  om
public void testEquals() {
    TextTitle t = new TextTitle("Title");
    XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t);
    XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t);
    assertTrue(a1.equals(a2));

    a1 = new XYTitleAnnotation(1.1, 2.0, t);
    assertFalse(a1.equals(a2));
    a2 = new XYTitleAnnotation(1.1, 2.0, t);
    assertTrue(a1.equals(a2));

    a1 = new XYTitleAnnotation(1.1, 2.2, t);
    assertFalse(a1.equals(a2));
    a2 = new XYTitleAnnotation(1.1, 2.2, t);
    assertTrue(a1.equals(a2));

    TextTitle t2 = new TextTitle("Title 2");
    a1 = new XYTitleAnnotation(1.1, 2.2, t2);
    assertFalse(a1.equals(a2));
    a2 = new XYTitleAnnotation(1.1, 2.2, t2);
    assertTrue(a1.equals(a2));
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    DateAxis dateaxis = new DateAxis("Year");
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);//from w w  w .  j  ava2 s  . c  o m
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Tonnes");
    numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
    StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.29999999999999999D);
    stackedxybarrenderer.setRenderAsPercentages(true);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, new Color(64, 0, 0), 0.0F, 0.0F, Color.red);
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, new Color(0, 64, 0), 0.0F, 0.0F, Color.green);
    stackedxybarrenderer.setSeriesPaint(0, gradientpaint);
    stackedxybarrenderer.setSeriesPaint(1, gradientpaint1);
    stackedxybarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    stackedxybarrenderer.setDrawBarOutline(false);
    stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2} tonnes",
            new SimpleDateFormat("yyyy"), new DecimalFormat("#,##0")));
    XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    JFreeChart jfreechart = new JFreeChart("Waste Management", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    jfreechart.addSubtitle(new TextTitle("St Albans City and District Council"));
    return jfreechart;
}

From source file:sanger.team16.gui.genevar.eqtl.query.SNPGeneAssocPlot.java

public SNPGeneAssocPlot(List<Tuple> tuples, double max, double min) throws ArrayIndexOutOfBoundsException {
    JPanel mainPanel = new JPanel(new GridLayout(0, 3));
    mainPanel.setBackground(Color.white);

    int size = tuples.size();
    for (int i = 0; i < size; i++) {
        Tuple tuple = tuples.get(i);//from www. ja v  a2  s. co  m
        String populationName = tuple.populationName;

        // if (trait.expressionRanks != null) {   // BUG FIXED 02/02/10
        if (tuple.phenotypes != null && tuple.phenotypes.length != 0) {
            CategoryDataset dataset = this.createDataset(tuple);
            JFreeChart chart = createChart(populationName, dataset, max, min);
            chart.setBackgroundPaint(Color.white);

            TextTitle textTitle = new TextTitle(tuple.subtitle);
            textTitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
            //subtitle1.setPosition(RectangleEdge.BOTTOM);
            textTitle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            chart.addSubtitle(textTitle);

            ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(this.getAutoPreferredSize()); // Original Dimension(680, 420)
            mainPanel.add(chartPanel);

        } else {
            BaseJPane empty = new BaseJPane(2, 50, 0, 0);
            empty.setPreferredSize(this.getAutoPreferredSize());
            BaseJPane na = new BaseJPane();
            na.setLayout(new BorderLayout());

            JLabel name = new JLabel("      " + populationName);
            name.setFont(new Font("Arial", Font.BOLD, 12));
            name.setForeground(Color.gray);
            na.add(name, BorderLayout.PAGE_START);

            JLabel message = new JLabel("Not Available");
            message.setForeground(Color.lightGray);
            na.add(message, BorderLayout.CENTER);

            empty.add(Box.createHorizontalGlue());
            empty.add(na);
            empty.add(Box.createHorizontalGlue());
            empty.setBaseSpringBox();

            mainPanel.add(empty);
        }
    }

    this.add(mainPanel);
}

From source file:unikn.dbis.univis.visualization.chart.AbstractChart.java

/**
 * Sets the subtitels and the legend.// w ww  .ja va  2s .  c o m
 *
 * @param total  The total amount of the chart.
 * @param legend The legend of the chart
 */
public void setSubtitles(int total, LegendTitle legend) {

    String totalName = "Total: " + total;
    TextTitle totalTitle = new TextTitle(totalName);
    subtitleList.add(totalTitle);
    if (getItemsCount() < 15) {
        subtitleList.add(legend);
    }
    chart.setSubtitles(subtitleList);
}

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

public JFreeChart createChart() throws OperationException {
    if (dataset == null) {
        throw new OperationException("Cannot create Time series chart: cause -> dataset null!");
    }//from w  w w .j  a  v  a  2 s  .c o m

    chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, showLegend, showTooltip, false);

    if (showShapes) {
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) plot.getRenderer();
        render.setBaseShapesVisible(true);
    }

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

    //displaying labels
    if (showLabels) {
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) plot.getRenderer();
        render.setItemLabelGenerator(new StandardXYItemLabelGenerator());
        render.setItemLabelsVisible(true);
    }

    return chart;

}

From source file:sas.BarChart.java

public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) {
    JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle(t));
    TextTitle texttitle = new TextTitle("");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER);
    jfreechart.addSubtitle(texttitle);//  w w  w.  j a va2 s .  c o  m
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinesVisible(false);
    java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png");
    if (url != null) {
        ImageIcon imageicon = new ImageIcon(url);
        jfreechart.setBackgroundImage(imageicon.getImage());
        categoryplot.setBackgroundPaint(null);
    }
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChartUtilities.applyCurrentTheme(jfreechart);
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
    lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
    lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    return jfreechart;
}

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

/**
 * Creates a new demo.//w w w  .j ava2 s.  com
 *
 * @param title the frame title.
 * @param pf
 */
public HybridRoundNumberReport(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, 14);
    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 + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1350, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

/**
 * Creates a new demo.// ww  w .j av a2s .  c o  m
 *
 * @param title the frame title.
 * @param pf
 */
public ECALinfoCollected(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, 16);
    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("ECALinfoColl" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ECALinfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ECALinfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.sonar.server.charts.deprecated.BaseChart.java

protected void configureChartTitle(JFreeChart chart, String title) {
    if (title != null && title.length() > 0) {
        TextTitle textTitle = new TextTitle(title);
        chart.setTitle(textTitle);/*w  w  w  .j a va  2s.com*/
    }
}

From source file:sentimentanalyzer.ChartController.java

public void createAndPopulatePieChart(JPanel pnlPieChart, double positiveValue, double negativeValue,
        double neutralValue) {

    DefaultPieDataset data = new DefaultPieDataset();

    data.setValue(Pos, positiveValue /*count for 1 */);
    data.setValue(Neu, neutralValue /*count for 0 */);
    data.setValue(Neg, negativeValue /*count for -1 */);

    JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend?
            false, // tooltips?
            false // URLs?
    );/*from w  w  w. j av a  2s.  c o  m*/
    ChartPanel CP = new ChartPanel(chart);

    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY);
    plot.setExplodePercent(Pos, 0.02);
    plot.setExplodePercent(Neg, 0.02);
    plot.setExplodePercent(Neu, 0.02);

    double sum = positiveValue + negativeValue + neutralValue;
    int z = (int) sum;

    //Customize PieChart to show absolute values and percentages;

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(gen);

    TextTitle legendText = new TextTitle("The total number of tweets: " + z);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    pnlPieChart.removeAll();

    pnlPieChart.setLayout(new java.awt.BorderLayout());
    pnlPieChart.add(CP, BorderLayout.CENTER);

}