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

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

Introduction

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

Prototype

public void setPosition(RectangleEdge position) 

Source Link

Document

Sets the position for the title and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java

/**
 * Creates a new demo.//from  w  ww.j a v  a 2  s.  c  o  m
 *
 * @param title the frame title.
 * @param pf
 */
public BestAgentsRoundInfoCollected(final String title, ArrayList<Double> pf) {

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    /*for (String mode : aMode) {
    info.put(mode, new ArrayList());
    }*/

    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);
    System.out.println("info" + info);
    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round of Best Agents " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("BestAgentsRound" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.sf.jasperreports.components.spiderchart.FillSpiderChart.java

protected JFreeChart evaluateChart(byte evaluation) throws JRException {
    maxValue = (Double) fillContext.evaluate(getPlot().getMaxValueExpression(), evaluation);
    titleText = (String) fillContext.evaluate(getChartSettings().getTitleExpression(), evaluation);
    subtitleText = (String) fillContext.evaluate(getChartSettings().getSubtitleExpression(), evaluation);
    anchorName = (String) fillContext.evaluate(getChartSettings().getAnchorNameExpression(), evaluation);
    hyperlinkReference = (String) fillContext.evaluate(getChartSettings().getHyperlinkReferenceExpression(),
            evaluation);// ww  w  .j ava2s .  c  o m
    hyperlinkAnchor = (String) fillContext.evaluate(getChartSettings().getHyperlinkAnchorExpression(),
            evaluation);
    hyperlinkPage = (Integer) fillContext.evaluate(getChartSettings().getHyperlinkPageExpression(), evaluation);
    hyperlinkTooltip = (String) fillContext.evaluate(getChartSettings().getHyperlinkTooltipExpression(),
            evaluation);
    hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(getChartSettings(),
            expressionEvaluator, evaluation);

    dataset.evaluateDatasetRun(evaluation);
    dataset.finishDataset();

    chartHyperlinkProvider = new CategoryChartHyperlinkProvider(dataset.getItemHyperlinks());

    bookmarkLevel = getChartSettings().getBookmarkLevel();

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot((DefaultCategoryDataset) dataset.getCustomDataset());

    if (getPlot().getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(getPlot().getAxisLineColor());
    }
    if (getPlot().getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(getPlot().getAxisLineWidth()));
    }
    if (getPlot().getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(getPlot().getBackcolor());
    }
    if (getPlot().getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(getPlot().getBackgroundAlpha());
    }
    if (getPlot().getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(getPlot().getForegroundAlpha());
    }
    if (getPlot().getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(getPlot().getHeadPercent());
    }
    if (getPlot().getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(getPlot().getInteriorGap());
    }
    if (getPlot().getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(getPlot().getLabelColor());
    }
    if (getPlot().getLabelFont() != null) {
        spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(getPlot().getLabelFont(), Locale.getDefault()));
    }
    if (getPlot().getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(getPlot().getLabelGap());
    }
    if (maxValue != null) {
        spiderWebPlot.setMaxValue(maxValue);
    }
    if (getPlot().getRotation() != null) {
        spiderWebPlot.setDirection(getPlot().getRotation().getRotation());
    }
    if (getPlot().getStartAngle() != null) {
        spiderWebPlot.setStartAngle(getPlot().getStartAngle());
    }
    if (getPlot().getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(getPlot().getTableOrder().getOrder());
    }
    if (getPlot().getWebFilled() != null) {
        spiderWebPlot.setWebFilled(getPlot().getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

    Font titleFont = getChartSettings().getTitleFont() != null
            ? JRFontUtil.getAwtFont(getChartSettings().getTitleFont(), Locale.getDefault())
            : TextTitle.DEFAULT_FONT;

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    if (chartSettings.getBackcolor() != null) {
        jfreechart.setBackgroundPaint(chartSettings.getBackcolor());
    }

    RectangleEdge titleEdge = getEdge(getChartSettings().getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (getChartSettings().getTitleColor() != null) {
            title.setPaint(getChartSettings().getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (getChartSettings().getSubtitleColor() != null) {
            subtitle.setPaint(getChartSettings().getSubtitleColor());
        }

        if (getChartSettings().getSubtitleColor() != null) {
            Font subtitleFont = getChartSettings().getSubtitleFont() != null
                    ? JRFontUtil.getAwtFont(getChartSettings().getSubtitleFont(), Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (getChartSettings().getLegendColor() != null) {
                legend.setItemPaint(getChartSettings().getLegendColor());
            }
            if (getChartSettings().getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(getChartSettings().getLegendBackgroundColor());
            }

            if (getChartSettings().getLegendFont() != null) {
                legend.setItemFont(
                        JRFontUtil.getAwtFont(getChartSettings().getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(getChartSettings().getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }
    return jfreechart;

}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createPieDatasetChart(final PieDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    PiePlot plot = null;//w  w  w. j a  v a 2 s.co  m
    plot = chartDefinition.isThreeD() ? new PiePlot3D(chartDefinition) : new PiePlot(chartDefinition);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart pieChart = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); //$NON-NLS-1$ //$NON-NLS-2$
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(title);
    pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        plot.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        plot.setURLGenerator(urlGenerator);
    }

    return pieChart;
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createMultiplePieChart(final CategoryDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    TableOrder order = TableOrder.BY_ROW;
    // boolean tooltips = true;
    // boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    if (order == null) {
        throw new IllegalArgumentException(
                Messages.getInstance().getString("JFreeChartEngine.ERROR_0001_NULL_ORDER_ARGUMENT")); //$NON-NLS-1$
    }/*  w ww  .j  av a2  s  .c  o m*/
    MultiplePiePlot plot = new MultiplePiePlot(chartDefinition);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    plot.setDataExtractOrder(order);

    JFreeChart pieCharts = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
    JFreeChart pieChart = plot.getPieChart();
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); //$NON-NLS-1$ //$NON-NLS-2$
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
    plot.setPieChart(pieChart);

    // if (tooltips) {
    // PieToolTipGenerator tooltipGenerator = new
    // StandardPieToolTipGenerator();
    // PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setToolTipGenerator(tooltipGenerator);
    // }

    // if (urls) {
    // PieURLGenerator urlGenerator = new StandardPieURLGenerator();
    // PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setURLGenerator(urlGenerator);
    // }

    return pieCharts;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
* Creates a chart that displays multiple pie plots.  The chart object     
* returned by this method uses a {@link MultiplePiePlot} instance as the    
* plot.    /*from w ww . j  a va  2  s .  co m*/
*    
* @param title  the chart title (<code>null</code> permitted).    
* @param dataset  the dataset (<code>null</code> permitted).    
* @param order  the order that the data is extracted (by row or by column)     
*               (<code>null</code> not permitted).    
* @param legend  include a legend?    
* @param tooltips  generate tooltips?    
* @param urls  generate URLs?    
*    
* @return A chart.    
*/
public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order,
        boolean legend, boolean tooltips, boolean urls) {

    if (order == null) {
        throw new IllegalArgumentException("Null 'order' argument.");
    }
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(order);
    plot.setBackgroundPaint(null);
    plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:KIDLYFactory.java

/**
 * Creates a chart that displays multiple pie plots.  The chart object
 * returned by this method uses a {@link MultiplePiePlot} instance as the
 * plot./*from   w w w. ja  va 2s .  c  o  m*/
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param order  the order that the data is extracted (by row or by column)
 *               (<code>null</code> not permitted).
 * @param legend  include a legend?
 * @param tooltips  generate tooltips?
 * @param urls  generate URLs?
 *
 * @return A chart.
 */
public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order,
        boolean legend, boolean tooltips, boolean urls) {

    if (order == null) {
        throw new IllegalArgumentException("Null 'order' argument.");
    }
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(order);
    plot.setBackgroundPaint(null);
    plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

private void computeCoefficientOfDetermination() {
    int numberOfItems = scatterpointsDataset.getSeries(0).getItemCount();
    double arithmeticMeanOfX = 0; //arithmetic mean of X
    double arithmeticMeanOfY = 0; //arithmetic mean of Y
    double varX = 0; //variance of X
    double varY = 0; //variance of Y
    double coVarXY = 0; //covariance of X and Y;
    //compute arithmetic means
    for (int i = 0; i < numberOfItems; i++) {
        arithmeticMeanOfX += scatterpointsDataset.getXValue(0, i);
        arithmeticMeanOfY += scatterpointsDataset.getYValue(0, i);
    }//from www  . j  a v  a  2s  . co m
    arithmeticMeanOfX /= numberOfItems;
    arithmeticMeanOfY /= numberOfItems;
    //compute variances and covariance
    for (int i = 0; i < numberOfItems; i++) {
        varX += Math.pow(scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX, 2);
        varY += Math.pow(scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY, 2);
        coVarXY += (scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX)
                * (scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY);
    }
    //computation of coefficient of determination
    double r2 = Math.pow(coVarXY, 2) / (varX * varY);
    r2 = MathUtils.round(r2, Math.pow(10.0, 5));

    final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0);
    final double intercept = coefficients[0];
    final double slope = coefficients[1];
    final String linearEquation;
    if (intercept >= 0) {
        linearEquation = "y = " + (float) slope + "x + " + (float) intercept;
    } else {
        linearEquation = "y = " + (float) slope + "x - " + Math.abs((float) intercept);
    }

    TextTitle tt = new TextTitle(linearEquation + "\nR = " + r2);
    tt.setTextAlignment(HorizontalAlignment.RIGHT);
    tt.setFont(chart.getLegend().getItemFont());
    tt.setBackgroundPaint(new Color(200, 200, 255, 100));
    tt.setFrame(new BlockBorder(Color.white));
    tt.setPosition(RectangleEdge.BOTTOM);

    r2Annotation = new XYTitleAnnotation(0.98, 0.02, tt, RectangleAnchor.BOTTOM_RIGHT);
    r2Annotation.setMaxWidth(0.48);
    getPlot().addAnnotation(r2Annotation);
}

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

/**
 * Creates and returns a sample time series chart.
 *
 * @return a sample time series chart./*from   ww  w .j  av a2s  .  c o  m*/
 */
public JFreeChart createTimeSeries1Chart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("timeseries.sample1.title");
    final String subtitle = this.resources.getString("timeseries.sample1.subtitle");
    final String domain = this.resources.getString("timeseries.sample1.domain");
    final String range = this.resources.getString("timeseries.sample1.range");
    final String copyrightStr = this.resources.getString("timeseries.sample1.copyright");
    final XYDataset data = DemoDatasetFactory.createTimeSeriesCollection3();
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data, true, true, false);

    // then customise it a little...
    final TextTitle title2 = new TextTitle(subtitle, new Font("SansSerif", Font.PLAIN, 12));
    //      title2.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0));
    chart.addSubtitle(title2);

    final TextTitle copyright = new TextTitle(copyrightStr, new Font("SansSerif", Font.PLAIN, 9));
    copyright.setPosition(RectangleEdge.BOTTOM);
    copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(copyright);

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setVerticalTickLabels(true);
    return chart;

}

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

/**
 * Creates a basic wafermap chart with a random dataset
 *
 * @return a wafermap chart//  w w w  .  j a v a 2s .  c o  m
 */
public JFreeChart createWaferMapChart() {
    final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(5);
    final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo", // title
            dataset, // wafermapdataset
            PlotOrientation.VERTICAL, // vertical = notchdown
            true, // legend
            false, // tooltips
            false);

    //        final Legend legend = chart.getLegend();
    //      legend.setAnchor(Legend.EAST);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9));
    copyright.setPosition(RectangleEdge.BOTTOM);
    copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(copyright);

    return chart;
}

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

/**
 * Creates a basic wafermap chart with a random dataset
 *
 * @return a wafermap chart//from  ww w  .j  a v  a  2s . c  o  m
 */
public JFreeChart createWaferMapChartValueIndexed() {
    final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(500);
    final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo - Value Indexed", // title
            dataset, // wafermapdataset
            PlotOrientation.VERTICAL, // vertical = notchdown
            true, // legend
            false, // tooltips
            false);

    //      final Legend legend = chart.getLegend();
    //    legend.setAnchor(Legend.EAST);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9));
    copyright.setPosition(RectangleEdge.BOTTOM);
    copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(copyright);

    return chart;
}