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, Font font) 

Source Link

Document

Creates a new title, using default attributes where necessary.

Usage

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

/**
 * Creates a new demo./*  www  .ja v  a  2  s  . co m*/
 * 
 * @param title  the frame title.
 */
public WaferMapChartDemo(final String title) {
    super(title);
    final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(5);
    final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo", // title
            dataset, // wafermapdataset
            PlotOrientation.VERTICAL, // vertical = notchdown
            true, // legend           
            false, // tooltips
            false);

    //        final Legend legend = chart.getLegend();
    //      legend.setAnchor(Legend.EAST);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9));
    copyright.setPosition(RectangleEdge.BOTTOM);
    copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(copyright);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 400));
    setContentPane(chartPanel);
}

From source file:com.netsteadfast.greenstep.action.CommonPieChartAction.java

private void fillChart(String title, List<String> names, List<String> colors, List<Float> values)
        throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.setValue(names.get(ix), values.get(ix));
    }/*  w  w w .  j  a  v  a2s  .co  m*/
    this.chart = ChartFactory.createPieChart3D(title, data, true, true, false);
    LegendTitle legend = this.chart.getLegend();
    legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9));
    PiePlot plot = (PiePlot) this.chart.getPlot();
    plot.setCircular(true);
    plot.setBackgroundAlpha(0.9f);
    plot.setForegroundAlpha(0.5f);
    plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14));
    TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months",
            new Font("SansSerif", 0, 11));
    jfreechart.addSubtitle(texttitle);//from  www.  ja  v  a  2s . co m
    jfreechart.addSubtitle(texttitle1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setUpperMargin(0.12D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setAutoRangeIncludesZero(false);
    XYTextAnnotation xytextannotation = null;
    Font font = new Font("SansSerif", 0, 9);
    xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    return jfreechart;
}

From source file:com.okmich.hackerday.client.tool.dashboard.ReportItemPanel.java

/**
 *
 * @return A panel./*from   www.  j  av  a2s .c om*/
 */
public JPanel createChartPanel() {
    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            getChartDataset(), // data
            true, // include legend
            true, false);

    TextTitle textTitle = new TextTitle(title, new Font("SansSerif", Font.BOLD, 16));
    chart.setTitle(textTitle);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);

    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.addMouseListener(new MouseListenerImpl(this));

    return this.chartPanel;
}

From source file:de.berlios.statcvs.xml.chart.AbstractChart.java

/**
 * create chart with titles and credit information
 *//*from ww w.ja va  2s  . com*/
protected void setup(boolean defaultShowLegend) {
    if (chart == null) {
        throw new NullPointerException("Chart is not initialized");
    }

    if (this.subtitle != null && settings.getBoolean("showSubtitle", true)) {
        Font font = new Font("SansSerif", Font.PLAIN, 12);
        TextTitle title = new TextTitle(this.subtitle, font);
        title.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0));
        chart.addSubtitle(title);
    }

    if (settings.getBoolean("showCredit", true)) {
        Font font = new Font("SansSerif", Font.PLAIN, 9);
        TextTitle copyright = new TextTitle("generated by statcvs-xml\u00B2", font);
        copyright.setPosition(RectangleEdge.BOTTOM);
        copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        chart.addSubtitle(copyright);
    }

    if (!settings.getBoolean("showLegend", defaultShowLegend)) {
        chart.setLegend(null);
    }

    chart.setBackgroundPaint(Color.white);
}

From source file:com.orsonpdf.demo.PDFPieChartDemo1.java

/**
 * Creates a chart./*from   ww  w  .  j  a va  2 s.c o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", dataset, false, false,
            false);

    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

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

    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);
    plot.setShadowPaint(null);
    plot.setLabelShadowPaint(null);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 1.0f);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:org.jfree.fx.demo.FXGraphics2DDemo1.java

/**
 * Creates a chart.//from  ww w  .  j  a va 2s . c  o m
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", // title
            null, // x-axis label
            "US cents/lb", // y-axis label
            dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf",
            new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return chart;

}

From source file:org.jfree.graphics2d.demo.SVGPieChartDemo1.java

/**
 * Creates a chart.//from   w w w. j  a  v  a2 s  . com
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // chart title
            dataset);
    chart.removeLegend();

    // set a custom background for the chart
    chart.setBackgroundPainter(new GradientPainter(new Color(20, 20, 20), RectangleAnchor.TOP_LEFT,
            Color.DARK_GRAY, RectangleAnchor.BOTTOM_RIGHT));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPainter(null);
    plot.setInteriorGap(0.04);
    plot.setBorderPainter(null);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:uom.research.thalassemia.util.PieChartCreator.java

/**
 * Creates a chart./*from  w  w  w  .  j av  a  2 s  .  com*/
 *
 * @param dataset the dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            true, // no legend
            true, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    int itemIndex = 0;
    for (Object col : pieDataset.getKeys()) {
        plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]);
        if (itemIndex == pieDataset.getItemCount() - 1) {
            itemIndex = 0;
        }
        itemIndex++;
    }

    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:com.xilinx.ultrascale.gui.DMABarChart.java

private void makeChart() {
    dataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("", "Time Interval", "Throughput (Gbps)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(bg);/*w w w . j a v  a 2  s. c om*/
    TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15));
    ttitle.setPaint(Color.WHITE);
    chart.setTitle(ttitle);

    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    ValueAxis axis = plot.getRangeAxis();
    axis.setUpperBound(64.0);
    axis.setLowerBound(0.0);
    axis.setTickLabelPaint(new Color(185, 185, 185));
    axis.setLabelPaint(new Color(185, 185, 185));

    CategoryAxis caxis = plot.getDomainAxis();
    caxis.setTickLabelPaint(new Color(185, 185, 185));
    caxis.setLabelPaint(new Color(185, 185, 185));

    renderer.setItemMargin(0);
    renderer.setSeriesPaint(0, new Color(0x2e, 0x90, 0x18));//(0x17, 0x7b, 0x7c));
    renderer.setSeriesPaint(1, new Color(0x12, 0x45, 0x73));//(0xa2, 0x45, 0x73)
    renderer.setSeriesPaint(3, new Color(0xff, 0x80, 0x40));
    renderer.setSeriesPaint(2, new Color(0x6f, 0x2c, 0x85));
    renderer.setSeriesPaint(4, new Color(0xa1, 0x60, 0x98));
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000")));
    //renderer.setMaximumBarWidth(0.05);
    //        addDummy();
}