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:ch.algotrader.client.chart.ChartTab.java

public void init(ChartDefinitionVO chartDefinition) {

    // remove all components first
    this.removeAll();

    resetPopupMenu();/*from   w  w  w .java 2 s . c o m*/

    this.chartDefinition = chartDefinition;

    // create the plot
    XYPlot plot = new XYPlot();

    // add gridlines
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    // create the JFreeChart
    JFreeChart chart = new JFreeChart(plot);
    this.setChart(chart);

    // init the maps
    this.bars = new HashMap<>();
    this.indicators = new HashMap<>();
    this.markers = new HashMap<>();
    this.markersSelectionStatus = new HashMap<>();

    // init domain axis
    initDomainAxis(chartDefinition);

    // init range axis
    initRangeAxis(chartDefinition);

    // create a subtitle
    TextTitle title = new TextTitle();
    title.setFont(new Font("SansSerif", 0, 9));
    chart.addSubtitle(title);

    // crosshair
    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
}

From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java

private JFreeChart getMemoryChart(int intervalSize, List<MemoryData> memory) {

    if (null == memory || memory.isEmpty()) {
        return null;
    }/*www  . ja  va  2  s . com*/

    JFreeChart chart;

    TimeSeries freeSeries = new TimeSeries("Free");
    TimeSeries maxSeries = new TimeSeries("Max");
    TimeSeries totalSeries = new TimeSeries("Total");

    memory.remove(memory.size() - 1);

    for (MemoryData memoryEntry : memory) {
        freeSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getFreeMemory());

        maxSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getMaxMemory());

        totalSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getTotalMemory());
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(freeSeries);
    dataset.addSeries(maxSeries);
    dataset.addSeries(totalSeries);
    chart = ChartFactory.createTimeSeriesChart("eID Trust Service Memory Usage History",
            "Time (interval size " + intervalSize + " msec)", "Memory", dataset, true, false, false);

    chart.addSubtitle(new TextTitle(
            memory.get(0).getDate().toString() + " - " + memory.get(memory.size() - 1).getDate().toString()));

    chart.setBackgroundPaint(Color.WHITE);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRenderer(renderer);

    return chart;
}

From source file:hr.restart.util.chart.ChartXY.java

/**
 * Creates a BAR CHART/*from   w w w.j  av a 2s.c  om*/
 * @param dataset The org.jfree.data.CategoryDataset
 * @param title The title
 * @return org.jfree.chart.JFreeChart
 */
private JFreeChart createBarChart(final CategoryDataset dataset, String title, PlotOrientation orientation) {

    final JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            orientation, // the plot orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    // the subtitle from the combobox        
    if (jcb != null)
        chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString()));

    //subtitles setted by the user.
    if (getSubtitles() != null)
        for (int i = 0; i < getSubtitles().size(); i++) {
            chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString()));
        }

    final Plot plot = chart.getPlot();

    // get a reference to the plot for further customisation...
    final CategoryPlot categoryPlot = (CategoryPlot) plot;

    categoryPlot.setNoDataMessage("NO DATA!");

    categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });
    categoryPlot.setRenderer(renderer);

    renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);

    // inside
    //renderer.setBaseItemLabelPaint(Color.white);
    Font font = new Font("SansSerif", Font.PLAIN, 7);
    Font derive = font.deriveFont(Font.BOLD);
    renderer.setBaseItemLabelFont(derive);

    // margin
    final CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    //domainAxis.setBottomCategoryLabelPosition(new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER));
    domainAxis.setCategoryLabelPositions(new CategoryLabelPositions(
            new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_CENTER), // TOP
            new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER), // BOTTOM
            new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                    CategoryLabelWidthType.RANGE, 0.30f), // LEFT
            new CategoryLabelPosition(RectangleAnchor.RIGHT, TextBlockAnchor.CENTER_RIGHT,
                    CategoryLabelWidthType.RANGE, 0.30f) // RIGHT) 
    ));

    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0);
    renderer.setPositiveItemLabelPosition(p);

    if (comboBoxOrientation != null) {
        if (comboBoxOrientation.getSelectedItem() == "Vertikalni") {

            domainAxis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
        }
    }

    return chart;

}

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

/**
 * Creates a chart.//from  w w w  .j a v  a2 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", // 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:org.jfree.chart.demo.CombinedXYPlotDemo3.java

/**
 * Creates a combined XYPlot chart.//from ww w  .  j av a 2  s.  c  o  m
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create a default chart based on some sample data...
    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
    dataset0.addSeries(eur);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
    dataset1.addSeries(eur);
    dataset1.addSeries(mav);

    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    dataset2.addSeries(eur);

    JFreeChart chart = null;

    // make a common vertical axis for all the sub-plots
    final NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false); // override default

    // make a horizontally combined plot
    final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);

    // add subplot 1...
    final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null, new StandardXYItemRenderer());
    parent.add(subplot1, 1);

    // add subplot 2...
    final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, new StandardXYItemRenderer());
    parent.add(subplot2, 1);

    // add subplot 3...
    final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), null, new XYBarRenderer(0.20));
    parent.add(subplot3, 1);

    // now make the top level JFreeChart
    chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle("This is a subtitle", new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:hr.restart.util.chart.ChartXYZ.java

/**
  * Creates a BAR CHART.// w w  w . j  a va 2s .co  m
  * 
  * @param dataset The org.jfree.data.CategoryDataset
  * @param title The title
  * @return org.jfree.chart.JFreeChart
  */
final private JFreeChart createBarChart(final CategoryDataset dataset, String title) {

    final JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    //print the subtitles
    java.util.List subs = getSubtitles();
    if (subs != null) {
        for (int i = 0; i < subs.size(); i++) {
            chart.addSubtitle(new TextTitle(subs.get(i).toString()));
        }
    }

    //      NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    //plot.setBackgroundPaint(Color.lightGray);
    //plot.setDomainGridlinePaint(Color.white);
    //plot.setRangeGridlinePaint(Color.white);

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

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(getItemMargin());
    adjustBarRenderer(renderer);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(getCategoryMargin());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * Creates a chart./*from   w w w.j  a  v  a  2s.  co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);

    chart.setBackgroundPaint(Color.white);
    final TextTitle subtitle = new TextTitle("An area chart demonstration.  We use this subtitle "
            + " as an example of what happens when you get a really long title or subtitle.");
    subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
    subtitle.setPosition(RectangleEdge.TOP);
    //        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    chart.addSubtitle(subtitle);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.5f);

    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.seniorproject.augmentedreality.test.AreaChartDemo.java

/**
 * Creates a chart./*from w  w w  . j  ava 2  s  . c o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);

    chart.setBackgroundPaint(Color.white);
    final TextTitle subtitle = new TextTitle("An area chart demonstration.  We use this "
            + "subtitle as an example of what happens when you get a really long title or " + "subtitle.");
    subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
    subtitle.setPosition(RectangleEdge.TOP);
    //        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    chart.addSubtitle(subtitle);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.5f);

    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:sentimentanalyzer.ChartController.java

public void createAndPopulatePieChart(JPanel pnlPieChart, double positiveValue, double negativeValue,
        double neutralValue) {

    DefaultPieDataset data = new DefaultPieDataset();

    data.setValue(Pos, positiveValue /*count for 1 */);
    data.setValue(Neu, neutralValue /*count for 0 */);
    data.setValue(Neg, negativeValue /*count for -1 */);

    JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend?
            false, // tooltips?
            false // URLs?
    );//  w  ww.ja  va2  s  .  co  m
    ChartPanel CP = new ChartPanel(chart);

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

    plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY);
    plot.setExplodePercent(Pos, 0.02);
    plot.setExplodePercent(Neg, 0.02);
    plot.setExplodePercent(Neu, 0.02);

    double sum = positiveValue + negativeValue + neutralValue;
    int z = (int) sum;

    //Customize PieChart to show absolute values and percentages;

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(gen);

    TextTitle legendText = new TextTitle("The total number of tweets: " + z);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    pnlPieChart.removeAll();

    pnlPieChart.setLayout(new java.awt.BorderLayout());
    pnlPieChart.add(CP, BorderLayout.CENTER);

}

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

/**
 * Creates a chart.// w  w w  .  j  a  v  a  2 s. co  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;

}