Example usage for org.jfree.chart JFreeChart addSubtitle

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

Introduction

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

Prototype

public void addSubtitle(Title subtitle) 

Source Link

Document

Adds a chart subtitle, and notifies registered listeners that the chart has been modified.

Usage

From source file:moviedatas.View.SpiderWebChart.java

/**
 * Creates a sample chart./*from  w  w w.  jav a 2 s.  c om*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    SpiderWebPlot plot = new SpiderWebPlot(dataset);
    plot.setStartAngle(54);
    plot.setInteriorGap(0.40);
    //plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, false);
    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);
    //ChartUtilities.applyCurrentTheme(chart);
    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);//  www.  ja  v  a2s  .  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:org.spf4j.perf.impl.chart.Charts.java

public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values,
        final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
    final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis,
            stepMillis);/*from  w w  w. ja  v  a  2 s  .co  m*/
    NumberAxis xAxis = new NumberAxis("Time");
    xAxis.setStandardTickUnits(dataSet.createXTickUnits());
    xAxis.setLowerMargin(0);
    xAxis.setUpperMargin(0);
    xAxis.setVerticalTickLabels(true);
    NumberAxis yAxis = new NumberAxis(uom);
    yAxis.setStandardTickUnits(dataSet.createYTickUnits());
    yAxis.setLowerMargin(0);
    yAxis.setUpperMargin(0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    PaintScale scale;
    if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
        if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
            scale = new InverseGrayScale(0, 1);
        } else {
            scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
        }
    } else {
        scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
    }
    renderer.setPaintScale(scale);
    renderer.setBlockWidth(1);
    renderer.setBlockHeight(1);
    XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);
    JFreeChart chart = new JFreeChart(chartName, plot);
    PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
    legend.setMargin(0, 5, 0, 5);
    chart.addSubtitle(legend);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:eu.delving.sip.base.ReportChartHelper.java

public static JPanel createPresenceChart(DataSet dataSet, String prefix, int[] presence, int totalRecords) {
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    int index = 0;
    for (RecDef.Check check : RecDef.Check.values()) {
        data.addValue(presence[index], "Presence", check);
        index++;//from w  w w. ja  v a 2 s  .  c  o m
    }
    JFreeChart chart = ChartFactory.createBarChart(
            String.format("Field presence in %s / %s", dataSet.getSpec(), prefix), "Field",
            String.format("Record count of %d records", totalRecords), data, PlotOrientation.VERTICAL, false,
            true, false);
    chart.addSubtitle(new TextTitle("Field Presence"));
    return finishBarChart(chart, new Color(218, 112, 214));
}

From source file:ChartUsingJava.CombinedXYPlotDemo1.java

/**
 * Creates an overlaid chart.//from  w  w w . jav  a 2 s.  c o  m
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {

    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {
        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            } else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}

From source file:eu.delving.stats.ChartHelper.java

private static JFreeChart createFieldFrequencyChart(Stats.RecordStats recordStats, Path path, String name) {
    Stats.Histogram histogram = recordStats.frequencies.get(path);
    if (histogram == null)
        return null;
    List<Stats.Counter> sorted = sort(histogram.counterMap.values(), MAX_BAR_CHART_SIZE,
            recordStats.recordCount);//from  w ww .  j  av  a2 s  .  com
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    data.addValue(histogram.absent, "Frequency", "0");
    for (Stats.Counter counter : sorted)
        data.addValue(counter.count, "Frequency", counter.value);
    JFreeChart chart = ChartFactory.createBarChart(String.format("Frequency within record in %s", name),
            "Occurrences", "Frequency", data, PlotOrientation.VERTICAL, false, true, false);
    chart.addSubtitle(new TextTitle(path.toString()));
    return finishBarChart(chart, new Color(30, 144, 225));
}

From source file:eu.delving.stats.ChartHelper.java

private static JFreeChart createWordCountChart(Stats.ValueStats valueStats, Path path, String name) {
    if (valueStats.wordCounts == null)
        return null;
    List<Stats.Counter> sorted = sort(valueStats.wordCounts.counterMap.values(), MAX_BAR_CHART_SIZE,
            valueStats.total);//from   w ww.  j a  v  a 2  s  .  com
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    for (Stats.Counter counter : sorted)
        data.addValue(counter.count, "Count", counter.value);
    JFreeChart chart = ChartFactory.createBarChart(String.format("Word count per occurrence in %s", name),
            "Number of Words", "Record count", data, PlotOrientation.VERTICAL, false, true, false);
    chart.addSubtitle(new TextTitle(path.toString()));
    return finishBarChart(chart, new Color(218, 112, 214));
}

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

private static JFreeChart createChart6(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 w  w w  . jav 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:demo.BarChartDemo11.java

/**
 * Creates a sample chart.//  w  w  w  .j a v  a2s .  co m
 *
 * @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: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);
    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   w ww .j a va  2 s.  com
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}