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

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

Introduction

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

Prototype

public void setTextAlignment(HorizontalAlignment alignment) 

Source Link

Document

Sets the text alignment and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param chart/*from w w w  .ja  v  a 2 s.  c o m*/
 * @return
 */
private static void configureTitleAndLegend(final JFreeChart chart, final AbstractChart adapter) {

    final TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(new Font("Arial", Font.BOLD, 12));
        // title.setBackgroundPaint(Color.CYAN);
        title.setTextAlignment(HorizontalAlignment.LEFT);
        title.setHorizontalAlignment(HorizontalAlignment.CENTER);
        title.setMargin(0, 4, 5, 6);
    }

    if (chart.getLegend() != null) {
        chart.removeLegend();

        final LegendTitle legend = new LegendTitle(chart.getPlot(), new SNColumnArrangement(0, 0),
                new ColumnArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, 0));

        legend.setItemFont(LEGEND_FONT);
        legend.setPosition(RectangleEdge.BOTTOM);
        legend.setHorizontalAlignment(HorizontalAlignment.CENTER);
        legend.setBackgroundPaint(Color.WHITE);
        legend.setFrame(new LineBorder());
        legend.setMargin(0, 4, 5, 6);

        chart.addLegend(legend);

        // Now we'll try to remove any duplicate items from the legend..
        final Map<String, Integer> keys = new HashMap<String, Integer>();
        final LegendItemCollection items = new LegendItemCollection();

        for (LegendItemSource source : legend.getSources()) {

            for (int i = 0; i < source.getLegendItems().getItemCount(); i++) {

                final LegendItem item = source.getLegendItems().get(i);
                if (!keys.containsKey(item.getLabel())) {
                    keys.put(item.getLabel(), i);
                    items.add(item);
                }
            }
        }

        legend.setSources(new LegendItemSource[] { new LegendItemSource() {

            /*
             * (non-Javadoc)
             * 
             * @see org.jfree.chart.LegendItemSource#getLegendItems()
             */
            public LegendItemCollection getLegendItems() {
                return items;
            }

        } });
    }
}

From source file:com.greenpepper.confluence.macros.historic.AbstractChartBuilder.java

protected void customizeTitle(TextTitle title, Font font) {
    title.setFont(font);//from  w ww.  j  av  a2  s.c o  m
    title.setTextAlignment(HorizontalAlignment.LEFT);
    title.setPaint(Color.BLACK);
    title.setBackgroundPaint(TRANSPARENT_COLOR);
}

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

private JFreeChart getPerformanceChart(int intervalSize, List<PerformanceData> performance,
        int expectedRevoked) {
    TimeSeries series = new TimeSeries("Success");
    TimeSeries revokedSeries = new TimeSeries("Revoked");
    TimeSeries failureSeries = new TimeSeries("Failures");

    performance.remove(performance.size() - 1);
    if (performance.isEmpty()) {
        JOptionPane.showMessageDialog(null, "test did not run long enough");
        return null;
    }//  www.j a  v a  2 s.c  o  m

    JFreeChart chart;

    int totalCount = 0;
    int totalRevoked = 0;
    int totalFailures = 0;

    for (PerformanceData performanceEntry : performance) {
        series.add(new Second(performanceEntry.getDate()), performanceEntry.getCount());
        totalCount += performanceEntry.getCount();

        revokedSeries.add(new Second(performanceEntry.getDate()), performanceEntry.getRevoked());
        totalRevoked += performanceEntry.getRevoked();

        failureSeries.add(new Second(performanceEntry.getDate()), performanceEntry.getFailures());
        totalFailures += performanceEntry.getFailures();
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(revokedSeries);
    dataset.addSeries(failureSeries);
    chart = ChartFactory.createTimeSeriesChart("eID Trust Service Performance History",
            "Time (interval size " + intervalSize + " msec)", "Number of XKMS requests", dataset, true, false,
            false);

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

    TextTitle info = new TextTitle("Total number of successful requests: " + totalCount);
    info.setTextAlignment(HorizontalAlignment.LEFT);
    info.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(info);

    TextTitle info2 = new TextTitle(
            "Total number of revoked: " + totalRevoked + " expected=" + expectedRevoked);
    info2.setPosition(RectangleEdge.BOTTOM);
    info2.setTextAlignment(HorizontalAlignment.LEFT);
    chart.addSubtitle(info2);

    TextTitle info3 = new TextTitle("Total number of failures: " + totalFailures);
    info3.setPosition(RectangleEdge.BOTTOM);
    info3.setTextAlignment(HorizontalAlignment.LEFT);
    chart.addSubtitle(info3);

    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: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);
    }/* w  w  w.ja v a 2 s . com*/
    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);
}