Example usage for org.jfree.chart JFreeChart getTitle

List of usage examples for org.jfree.chart JFreeChart getTitle

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getTitle.

Prototype

public TextTitle getTitle() 

Source Link

Document

Returns the main chart title.

Usage

From source file:fr.irit.smac.libs.tooling.examples.plot.local.LocalChart.java

public static void main(String[] args) {

    // First, we inform the server that the chart "Layer" must be of type
    // PLOT// w  w w  .  j  ava  2 s .  c  o m
    AgentPlot.getServer().configChart("Layer", ChartType.PLOT);

    // Add plots to the chart "Layer" for serie #0
    AgentPlot.getChart("Layer").add(1, 2);
    AgentPlot.getChart("Layer").add(2, 2.5);
    AgentPlot.getChart("Layer").add(2, 3);

    // Add plots to the chart "Layer" for serie "My serie"
    AgentPlot.getChart("Layer").add("My serie", 21, 2);
    AgentPlot.getChart("Layer").add("My serie", 12, 2.5);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // Add plots to the chart "My Chart" which will be created during this
    // call
    AgentPlot.getChart("My chart").add(2, 3);
    AgentPlot.getChart("My chart").add(3, 3);
    AgentPlot.getChart("My chart").add(3, 4);

    // Access the JFreeChart object (only from the server side)
    JFreeChart chart = ((AgentPlotChart) (AgentPlot.getChart("My chart"))).getJFreeChart();
    // Change its title
    chart.getTitle().setText("New title");

    // Close chart
    // AgentPlot.getChart("My chart").close();
    // AgentPlot.getChart("Layer").close();
}

From source file:fr.irit.smac.libs.tooling.plot.example.local.LocalChart.java

public static void main(String[] args) {

    // First, we inform the server that the chart "Layer" must be of type
    // PLOT/*from w w w  .  j a v a2s  . c om*/
    AgentPlot.getServer().configChart("Layer", EChartType.PLOT);

    // Add plots to the chart "Layer" for serie #0
    AgentPlot.getChart("Layer").add(1, 2);
    AgentPlot.getChart("Layer").add(2, 2.5);
    AgentPlot.getChart("Layer").add(2, 3);

    // Add plots to the chart "Layer" for serie "My serie"
    AgentPlot.getChart("Layer").add("My serie", 21, 2);
    AgentPlot.getChart("Layer").add("My serie", 12, 2.5);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // Add plots to the chart "My Chart" which will be created during this
    // call
    AgentPlot.getChart("My chart").add(2, 3);
    AgentPlot.getChart("My chart").add(3, 3);
    AgentPlot.getChart("My chart").add(3, 4);

    // Access the JFreeChart object (only from the server side)
    JFreeChart chart = ((AgentPlotChart) (AgentPlot.getChart("My chart"))).getJFreeChart();
    // Change its title
    chart.getTitle().setText("New title");

    // Close chart
    // AgentPlot.getChart("My chart").close();
    // AgentPlot.getChart("Layer").close();
}

From source file:org.matsim.contrib.util.chart.ChartWindowUtils.java

public static void showFrame(JFreeChart chart) {
    ChartFrame frame = new ChartFrame(chart.getTitle().getText(), chart);
    SwingUtils.showWindow(frame, false);
}

From source file:org.matsim.contrib.util.chart.ChartWindowUtils.java

public static void showDialog(JFreeChart chart, boolean modal) {
    JDialog dialog = newChartDialog(chart, chart.getTitle().getText(), modal);
    SwingUtils.showWindow(dialog, modal);
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

static void prettifyChart(JFreeChart chart) {
    // set title font
    chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 12));
    if (chart.getPlot() instanceof XYPlot) {
        XYPlot xYPlot = chart.getXYPlot();
        setupPlot(xYPlot);//from   ww  w. ja v  a  2 s.c  o m
    } else if (chart.getPlot() instanceof CategoryPlot) {
        CategoryPlot categoryPlot = chart.getCategoryPlot();
        setupPlot(categoryPlot);
    }
    setShadowVisible(chart, false);
}

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);/*w w  w .j a  v  a2s.  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.eobjects.datacleaner.util.ChartUtils.java

public static void applyStyles(JFreeChart chart) {
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(WidgetUtils.FONT_HEADER1);
        title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    }//from w ww.  j a v  a2s.c  o  m

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        Title subtitle = chart.getSubtitle(i);
        if (subtitle instanceof TextTitle) {
            ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL);
        }
    }

    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(WidgetUtils.FONT_SMALL);
    }

    // transparent background
    chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    chart.setBorderVisible(false);

    final Plot plot = chart.getPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d));
    plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlineVisible(true);

    if (plot instanceof PiePlot) {
        // tweaks for pie charts
        final PiePlot piePlot = (PiePlot) plot;
        piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setBaseSectionOutlineStroke(normalStroke);
        piePlot.setLabelFont(WidgetUtils.FONT_SMALL);
        piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT);
        piePlot.setLabelOutlineStroke(normalStroke);
        piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setSectionOutlinesVisible(false);
        piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE);
    } else if (plot instanceof CategoryPlot) {
        // tweaks for bar charts
        final CategoryPlot categoryPlot = (CategoryPlot) plot;

        int columnCount = categoryPlot.getDataset().getColumnCount();
        if (columnCount > 1) {
            categoryPlot.setDomainGridlinesVisible(true);
        } else {
            categoryPlot.setDomainGridlinesVisible(false);
        }
        categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);

        categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.setDrawingSupplier(new DCDrawingSupplier());

        final CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        renderer.setBaseOutlineStroke(wideStroke);

        if (renderer instanceof BarRenderer) {
            BarRenderer barRenderer = (BarRenderer) renderer;
            barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT);
            barRenderer.setBarPainter(new StandardBarPainter());
        }

    } else if (plot instanceof XYPlot) {
        // tweaks for line charts
        final XYPlot xyPlot = (XYPlot) plot;

        xyPlot.setDrawingSupplier(new DCDrawingSupplier());

        xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);

        final XYItemRenderer renderer = xyPlot.getRenderer();
        final int seriesCount = xyPlot.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            renderer.setSeriesStroke(i, wideStroke);
        }
    }
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo 9", null, "Value", categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    TextTitle texttitle = jfreechart.getTitle();
    texttitle.setBorder(0.0D, 0.0D, 1.0D, 0.0D);
    texttitle.setBackgroundPaint(new GradientPaint(0.0F, 0.0F, Color.red, 350F, 0.0F, Color.white, true));
    texttitle.setExpandToFitSpace(true);
    jfreechart.setBackgroundPaint(new GradientPaint(0.0F, 0.0F, Color.yellow, 350F, 0.0F, Color.white, true));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setNoDataMessage("NO DATA!");
    categoryplot.setBackgroundPaint(null);
    categoryplot.setInsets(new RectangleInsets(10D, 5D, 5D, 5D));
    categoryplot.setOutlinePaint(Color.black);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeGridlineStroke(new BasicStroke(1.0F));
    Paint apaint[] = createPaint();
    CustomBarRenderer custombarrenderer = new CustomBarRenderer(apaint);
    custombarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    categoryplot.setRenderer(custombarrenderer);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setRange(0.0D, 800D);//w w w.j a  va2s .  c  o  m
    numberaxis.setTickMarkPaint(Color.black);
    return jfreechart;
}

From source file:org.datacleaner.util.ChartUtils.java

public static void applyStyles(JFreeChart chart) {
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(WidgetUtils.FONT_HEADER1);
        title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    }//from w  ww  . j  a v  a2s  . com

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        Title subtitle = chart.getSubtitle(i);
        if (subtitle instanceof TextTitle) {
            ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL);
        }
    }

    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(WidgetUtils.FONT_SMALL);
    }

    // transparent background
    chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    chart.setBorderVisible(false);

    final Plot plot = chart.getPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d));
    plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlineVisible(true);

    if (plot instanceof PiePlot) {
        // tweaks for pie charts
        final PiePlot piePlot = (PiePlot) plot;
        piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setBaseSectionOutlineStroke(STROKE_NORMAL);
        piePlot.setLabelFont(WidgetUtils.FONT_SMALL);
        piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT);
        piePlot.setLabelOutlineStroke(STROKE_NORMAL);
        piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setSectionOutlinesVisible(false);
        piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE);
        piePlot.setDrawingSupplier(new DCDrawingSupplier());

    } else if (plot instanceof CategoryPlot) {
        // tweaks for bar charts
        final CategoryPlot categoryPlot = (CategoryPlot) plot;

        int columnCount = categoryPlot.getDataset().getColumnCount();
        if (columnCount > 1) {
            categoryPlot.setDomainGridlinesVisible(true);
        } else {
            categoryPlot.setDomainGridlinesVisible(false);
        }
        categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);

        categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.setDrawingSupplier(new DCDrawingSupplier());

        final CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        renderer.setBaseOutlineStroke(STROKE_WIDE);

        if (renderer instanceof BarRenderer) {
            BarRenderer barRenderer = (BarRenderer) renderer;
            barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT);
            barRenderer.setBarPainter(new StandardBarPainter());
        }

    } else if (plot instanceof XYPlot) {
        // tweaks for line charts
        final XYPlot xyPlot = (XYPlot) plot;

        xyPlot.setDrawingSupplier(new DCDrawingSupplier());

        xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);

        final XYItemRenderer renderer = xyPlot.getRenderer();
        final int seriesCount = xyPlot.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            renderer.setSeriesStroke(i, STROKE_WIDE);
        }
    }
}

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

public static void circularTheme(JFreeChart chart, String... colunsName) {
    chart.setBackgroundPaint(//w  w w.j a  v a2  s .  c  o 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);
}