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

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

Introduction

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

Prototype

public void setFont(Font font) 

Source Link

Document

Sets the font used to display the title string.

Usage

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);//  w  w w  .  j av a  2s  .  c  om
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.14999999999999999D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    lineandshaperenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("US Budget Deficit", "Year", true, "$ Billion",
            intervalxydataset, PlotOrientation.VERTICAL, false, false, false);
    TextTitle texttitle = new TextTitle("Source: http://www.cbo.gov/showdoc.cfm?index=1821&sequence=0#table12");
    texttitle.setFont(new Font("Dialog", 0, 8));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);//w  ww. j a va2 s  . c  om
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    xyitemrenderer.setBaseToolTipGenerator(standardxytooltipgenerator);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/*from  ww  w. j  a  va 2 s.  com*/
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryPointerAnnotation categorypointerannotation = new CategoryPointerAnnotation("Released 4-Dec-1998",
            "JDK 1.2", 1530D, -2.3561944901923448D);
    categorypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    categoryplot.addAnnotation(categorypointerannotation);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("US$ Treasury Yields", "Date", "Yield",
            xydataset, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    GregorianCalendar gregoriancalendar = new GregorianCalendar(2005, 10, 15);
    xyplot.setDomainAxis(new CustomDateAxis("Date", gregoriancalendar.getTime()));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*from w  w w.  j a  v a2s. co  m*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    jfreechart.addSubtitle(new TextTitle("November 2005"));
    TextTitle texttitle = new TextTitle("Source: http://www.econstats.com/r/r_am1.htm");
    texttitle.setFont(new Font("Dialog", 0, 9));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("US$ Treasury Yields", "Date", "Yield",
            xydataset, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    GregorianCalendar gregoriancalendar = new GregorianCalendar(2005, 10, 15);
    xyplot.setDomainAxis(new CustomDateAxis("Date", gregoriancalendar.getTime()));
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }//from   w ww. j  a  v  a  2s.  c om
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    jfreechart.addSubtitle(new TextTitle("November 2005"));
    TextTitle texttitle = new TextTitle("Source: http://www.econstats.com/r/r_am1.htm");
    texttitle.setFont(new Font("Dialog", 0, 9));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);
    return jfreechart;
}

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);/*from ww  w .ja 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:com.globalsight.util.JfreeCharUtil.java

public static void drawPieChart2D(String title, Map<String, Double> datas, File OutFile) {
    PieDataset dataset = buildDatas(datas);
    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
    chart.setBackgroundPaint(Color.white);
    plot.setCircular(true);/*  ww w.j  a  v a2  s  .  c  om*/
    TextTitle textTitle = new TextTitle(title);
    Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20);
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    FileOutputStream fos_jpg = null;

    try {
        fos_jpg = new FileOutputStream(OutFile);
        ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null);
        fos_jpg.close();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
    }
}

From source file:com.globalsight.util.JfreeCharUtil.java

public static void drawPieChart3D(String title, Map<String, Double> datas, File OutFile) {
    PieDataset dataset = buildDatas(datas);
    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
    chart.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.7f);/*ww  w .jav a 2s  . c o m*/
    plot.setCircular(true);
    TextTitle textTitle = new TextTitle(title);
    Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20);
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    FileOutputStream fos_jpg = null;

    try {
        fos_jpg = new FileOutputStream(OutFile);
        ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null);
        fos_jpg.close();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
    }
}

From source file:com.haskins.cloudtrailviewer.utils.ChartFactory.java

private static ChartPanel createPieChart(String type, List<Entry<String, Integer>> events, int width,
        int height) {

    DefaultPieDataset dataset = new DefaultPieDataset();

    for (Map.Entry<String, Integer> event : events) {
        dataset.setValue(event.getKey(), event.getValue());
    }//from  w  w  w.ja v  a2 s.  c  o  m

    JFreeChart jFChart;
    if (type.contains("3d")) {
        jFChart = org.jfree.chart.ChartFactory.createPieChart3D("", dataset, false, true, false);
    } else {
        jFChart = org.jfree.chart.ChartFactory.createPieChart("", dataset, false, true, false);
    }

    PiePlot plot = (PiePlot) jFChart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.01);
    plot.setOutlineVisible(false);
    plot.setLabelGenerator(null);

    // use gradients and white borders for the section colours
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    TextTitle t = jFChart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setFont(new Font("Arial", Font.BOLD, 16));

    final ChartPanel jChartPanel = new ChartPanel(jFChart, width, height, width, height, width, height, false,
            false, true, true, false, true);
    jChartPanel.setMinimumDrawWidth(0);
    jChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    jChartPanel.setMinimumDrawHeight(0);
    jChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    return jChartPanel;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset(1, 1.0D);
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "This chart shows various combinations of the useFillPaint and useOutlinePaint flags.");
    texttitle.setFont(new Font("Dialog", 0, 10));
    jfreechart.addSubtitle(texttitle);//w w  w.jav a  2  s  .  c o m
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 8D, 8D);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setSeriesShape(0, double1);
    xylineandshaperenderer.setSeriesPaint(0, Color.red);
    xylineandshaperenderer.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.gray);
    XYDataset xydataset1 = createDataset(2, 2D);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.red);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer1.setUseFillPaint(true);
    XYDataset xydataset2 = createDataset(3, 3D);
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    xyplot.setDataset(2, xydataset2);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.red);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer2.setUseOutlinePaint(true);
    XYDataset xydataset3 = createDataset(4, 4D);
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xyplot.setDataset(3, xydataset3);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    xylineandshaperenderer3.setSeriesShape(0, double1);
    xylineandshaperenderer3.setSeriesPaint(0, Color.red);
    xylineandshaperenderer3.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer3.setUseOutlinePaint(true);
    xylineandshaperenderer3.setUseFillPaint(true);
    XYDataset xydataset4 = createDataset(5, 5D);
    XYLineAndShapeRenderer xylineandshaperenderer4 = new XYLineAndShapeRenderer();
    xyplot.setDataset(4, xydataset4);
    xyplot.setRenderer(4, xylineandshaperenderer4);
    xylineandshaperenderer4.setSeriesShape(0, double1);
    xylineandshaperenderer4.setSeriesPaint(0, Color.red);
    xylineandshaperenderer4.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer4.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer4.setUseOutlinePaint(true);
    xylineandshaperenderer4.setUseFillPaint(true);
    xylineandshaperenderer4.setDrawOutlines(false);
    return jfreechart;
}