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:com.ohalo.cn.awt.JFreeChartTest3.java

public static void main(String[] args) throws Exception {
    JFreeChart chart = ChartFactory.createPieChart("???", getDataset(), true, true,
            false);//from   w  w w  . j  av a2 s  .  c o  m
    chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));

    LegendTitle legend = chart.getLegend(0);// Legend
    legend.setItemFont(new Font("", Font.BOLD, 14));
    PiePlot plot = (PiePlot) chart.getPlot();// Plot
    plot.setLabelFont(new Font("", Font.BOLD, 16));

    OutputStream os = new FileOutputStream("company.jpeg");// ??FileOutputStream?
    ChartUtilities.writeChartAsJPEG(os, chart, 1000, 800);
    // ??applicationchart??JPEG?3?4?

    os.close();// ?
}

From source file:DataCharts.LineGraph.java

public static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Customers by Month", "Months", "Customers", dataset);

    String fontName = "SansSerif";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle(" ", new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(false);/*from   w  ww . j av  a  2  s.  c om*/
    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);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setDrawSeriesLineAsPath(false);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);

    }
    return chart;

}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("State Executions - USA", "Year", true,
            "Number of People", intervalxydataset, PlotOrientation.VERTICAL, true, false, false);
    jfreechart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do",
            new Font("Dialog", 2, 10)));
    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);/*from   ww  w.  ja v a2  s . com*/
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

From source file:com.ohalo.cn.awt.JFreeChartTest2.java

public static JFreeChart createChart(CategoryDataset dataset) // ?
{
    JFreeChart chart = ChartFactory.createBarChart("hi", "", "?", dataset,
            PlotOrientation.VERTICAL, true, true, false); // JFreeChart
    chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));// ???hi?
    CategoryPlot plot = (CategoryPlot) chart.getPlot();// ?plot
    CategoryAxis categoryAxis = plot.getDomainAxis();// ??
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 12));// ??
    return chart;
}

From source file:st.jigasoft.dbutil.util.ReportTheme.java

public static void circularTheme(JFreeChart chart, String... colunsName) {
    chart.setBackgroundPaint(//from  w  ww .  j a  va2 s  .  co m
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    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);
    int iCount = 0;

    // use gradients and white borders for the section colours
    for (Object s : colunsName) {
        plot.setSectionPaint(s.toString(), createGradientPaint(new Color(200, 200, 255), colorItems(iCount++)));
        if (iCount == MAX_COLUNS_COLOR)
            iCount = 0;
    }

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

    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);
}

From source file:com.ouc.cpss.view.EmpSaleChartBuilder.java

private static JFreeChart createJFreeChart(CategoryDataset dataset) {
    /**/*  w  ww  . j a va  2  s .  c  om*/
     * JFreeChart
     */
    //?     
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //     
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //    
    standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
    //?     
    standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
    //?   
    ChartFactory.setChartTheme(standardChartTheme);
    //?
    JFreeChart jfreeChart = ChartFactory.createBarChart3D("", "", "?", dataset,
            PlotOrientation.VERTICAL, true, false, false);
    /**
     * JFreeChart
     */
    jfreeChart.setTitle(new TextTitle("", new Font("", Font.BOLD + Font.ITALIC, 20)));
    CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setLabelFont(new Font("", Font.ROMAN_BASELINE, 12));

    return jfreeChart;
}

From source file:demo.BarChartDemo11.java

/**
 * Creates a sample chart.//from w ww . j  ava2s.  com
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("Open Source Projects By License", "License", "Percent",
            dataset);
    chart.removeLegend();

    TextTitle source = new TextTitle(
            "Source: http://www.blackducksoftware.com/resources/data/top-20-licenses (as at 30 Aug 2013)",
            new Font("Dialog", Font.PLAIN, 9));
    source.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(source);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setDomainGridlinesVisible(true);

    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.8f);
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator("{1}: {2} percent",
            new DecimalFormat("0"));
    renderer.setBaseToolTipGenerator(tt);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.BLUE, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    return chart;

}

From source file:jmbench.plots.MemoryRelativeBarPlot.java

public MemoryRelativeBarPlot(String title) {
    chart = ChartFactory.createBarChart(title, // chart title
            "Operation", // domain axis label
            "Relative Memory", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*w w  w . j ava  2  s .  c o  m*/
    chart.addSubtitle(new TextTitle("(Smaller is Better)", new Font("SansSerif", Font.ITALIC, 12)));

    plot();
}

From source file:jmbench.plots.OverallRelativeAreaPlot.java

public OverallRelativeAreaPlot(String title, int sizes[]) {
    // createAreaChart

    chart = ChartFactory.createStackedAreaChart(title, // chart title
            "Size", // domain axis label
            "Relative Average Speed", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, false);//from  w w w.  j  av  a 2 s  .  co m

    chart.addSubtitle(new TextTitle("Weighted by Operation Speed. Larger is Better.",
            new Font("SansSerif", Font.ITALIC, 12)));

    plot = chart.getCategoryPlot();

    sizeNames = new String[sizes.length];
    for (int i = 0; i < sizes.length; i++) {
        sizeNames[i] = Integer.toString(sizes[i]);
    }

    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setBackgroundPaint(Color.WHITE);

    plot.setDomainGridlinesVisible(true);
}

From source file:ec.nbdemetra.benchmarking.calendarization.CalendarizationChartView.java

private static JFreeChart createChart(String title) {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);

    result.setTitle(new TextTitle(title, new Font("SansSerif", Font.PLAIN, 12)));

    XYPlot plot = result.getXYPlot();//from ww  w  .jav  a 2 s  .  com
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    LinesThickness linesThickness = LinesThickness.Thin;

    XYLineAndShapeRenderer daily = new XYLineAndShapeRenderer(true, false);
    daily.setAutoPopulateSeriesPaint(false);

    daily.setAutoPopulateSeriesStroke(false);
    daily.setBaseStroke(TsCharts.getStrongStroke(linesThickness));
    plot.setRenderer(DAILY_INDEX, daily);

    XYDifferenceRenderer difference = new XYDifferenceRenderer();
    difference.setAutoPopulateSeriesPaint(false);
    difference.setAutoPopulateSeriesStroke(false);
    difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness));
    plot.setRenderer(DIFF_INDEX, difference);

    XYLineAndShapeRenderer smooth = new XYLineAndShapeRenderer(true, false);
    smooth.setAutoPopulateSeriesPaint(false);
    smooth.setAutoPopulateSeriesStroke(false);
    smooth.setBaseStroke(TsCharts.getStrongStroke(linesThickness));
    plot.setRenderer(SMOOTH_INDEX, smooth);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    return result;
}