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:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            false, true, false);//from  w  w w.  java 2 s .c om

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.white);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();

    //defines colors 
    int seriesN = dataset.getSeriesCount();
    if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            Color color = new Color(Integer.decode(defaultColor).intValue());
            if (colorMap != null && colorMap.size() > 0)
                color = (Color) colorMap.get(serieName);
            if (color != null)
                renderer.setSeriesPaint(i, color);
        }
    }

    // add un interval  marker for the Y axis...
    if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("")
            && !yMarkerEndInt.equals("")) {
        Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt),
                Double.parseDouble(yMarkerEndInt));
        intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerY.setPaint(
                new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue()));
        //intMarkerY.setLabel(yMarkerLabel);
        intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(intMarkerY, Layer.BACKGROUND);
    }
    // add un interval  marker for the X axis...
    if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("")
            && !xMarkerEndInt.equals("")) {
        Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt),
                Double.parseDouble(xMarkerEndInt));
        intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerX.setPaint(
                new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue()));
        //intMarkerX.setLabel(xMarkerLabel);
        intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(intMarkerX, Layer.BACKGROUND);
    }
    // add a labelled marker for the Y axis...
    if (yMarkerValue != null && !yMarkerValue.equals("")) {
        Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue));
        markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!yMarkerColor.equals(""))
            markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue()));
        markerY.setLabel(yMarkerLabel);
        markerY.setLabelFont(new Font("Arial", Font.BOLD, 11));
        markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(markerY, Layer.BACKGROUND);
    }
    // add a labelled marker for the X axis...
    if (xMarkerValue != null && !xMarkerValue.equals("")) {
        Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue));
        markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!xMarkerColor.equals(""))
            markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue()));
        markerX.setLabel(xMarkerLabel);
        markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(markerX, Layer.BACKGROUND);
    }

    if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) {
        if (Double.valueOf(xRangeLow).doubleValue() > xMin)
            xRangeLow = String.valueOf(xMin);
        if (Double.valueOf(xRangeHigh).doubleValue() < xMax)
            xRangeHigh = String.valueOf(xMax);
        ValueAxis rangeAxis = plot.getRangeAxis();
        //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
        rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
    } else {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setAutoRange(true);
        rangeAxis.setRange(xMin, xMax);
    }

    if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) {
        if (Double.valueOf(yRangeLow).doubleValue() > yMin)
            yRangeLow = String.valueOf(yMin);
        if (Double.valueOf(yRangeHigh).doubleValue() < yMax)
            yRangeHigh = String.valueOf(yMax);
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setAutoRangeIncludesZero(false);
    } else {
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setAutoRange(true);
        domainAxis.setRange(yMin, yMax);
        domainAxis.setAutoRangeIncludesZero(false);
    }

    //add annotations if requested
    if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) {
        if (annotationMap == null || annotationMap.size() == 0)
            logger.error("Annotations on the chart are requested but the annotationMap is null!");
        else {
            int cont = 1;
            for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) {
                String text = (String) iterator.next();
                String pos = (String) annotationMap.get(text);
                double x = Double.parseDouble(pos.substring(0, pos.indexOf("__")));
                double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2));
                //default up position
                XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1,
                        x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                if (cont % 2 != 0)
                    //dx
                    annotation = new XYTextAnnotation(text, y,
                            x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                else
                    //sx
                    //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1));
                    annotation = new XYTextAnnotation(text, y, x - (text.length() - 1));

                annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
                //annotation.setRotationAngle(Math.PI / 4.0);
                annotation.setRotationAngle(0.0); // horizontal
                plot.addAnnotation(annotation);
                cont++;
            }
            renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
        }
    } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) {
        renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
    }
    if (legend == true) {

        drawLegend(chart);
    }
    return chart;
}

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

/**
 * Creates a new demo.//w  w w .  j av a 2s .  c om
 *
 * @param title the frame title.
 * @param pf
 */
public HybridRoundNumberReport(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    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, 14);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + 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("roundnumber1" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1350, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

/**
 * Creates a new demo./*from   www .  ja  va  2  s  . co  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public InformationCollected2(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    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("Information Collected " + 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("informationcollected2" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

/**
 * Creates a new demo./*from   ww  w .ja v a2 s . com*/
 *
 * @param title the frame title.
 * @param pf
 */
public HybridInformationCollected(final String title, ArrayList<Double> pf) {
    super(title);
    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);
    final CategoryAxis xAxis = new CategoryAxis("");
    final NumberAxis yAxis = new NumberAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    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, 12);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Total of Information Collected " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 12), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1300, 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("totalInformationCollected" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1300, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HybridInformationCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HybridInformationCollected.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private JFreeChart createPieChart(final Account a) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Objects.requireNonNull(a);/*  www.  j av  a2  s .  c om*/

    PieDataset data = createPieDataSet(a);
    PiePlot plot = new PiePlot(data);

    // rebuilt each time because they're based on the account's commodity
    CurrencyNode defaultCurrency = engine.getDefaultCurrency();
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);

    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);

    plot.setLabelGap(.02);
    plot.setInteriorGap(.1);

    // if we had to add a section for the account (because it has it's
    // own transactions, not just child accounts), separate it from children.
    if (data.getIndex(a) != -1) {
        plot.setExplodePercent(a, .10);
    }

    String title;

    // pick an appropriate title
    if (a.getAccountType() == AccountType.EXPENSE) {
        title = rb.getString("Title.PercentExpense");
    } else if (a.getAccountType() == AccountType.INCOME) {
        title = rb.getString("Title.PercentIncome");
    } else {
        title = rb.getString("Title.PercentDist");
    }

    title = title + " - " + a.getPathName();

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

    BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();

    String subtitle = valueFormat.format(total);
    if (!defaultCurrency.equals(a.getCurrencyNode())) {
        BigDecimal totalDefaultCurrency = total.multiply(a.getCurrencyNode().getExchangeRate(defaultCurrency));
        NumberFormat defaultValueFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
        subtitle += "  -  " + defaultValueFormat.format(totalDefaultCurrency);
    }
    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.SimpleXY_ChartPanel.java

private JFreeChart createChart(XY_PlotType type, Object userObject, Object userElement) {
    SMT_UpdateService updateService = SMT_UpdateService.getInstance();
    OMS_Collection history = updateService.getCollection();

    if ((history == null) || (history.getSize() < 2)) {
        // need at least two datapoints to this chart to make sense
        logger.severe("OMS Delta unavailable, cannot createChart(), must wait for more historical snapshots");
        MessageManager.getInstance().postMessage(
                new SmtMessage(SmtMessageType.SMT_MSG_SEVERE, "Cannot build chart without historical data"));
        return null;
    }//from   w  ww.java2 s.com

    MessageManager.getInstance()
            .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building Plot"));
    long deltaPeriod = history.getAveDeltaSeconds();

    // the primary dataset of the desired counter which will be axis1  
    XYDataset dataset1 = createDataset(history, userObject, userElement);

    // most axis are in counts (and delta counts) but utilization is in percentages
    String axisLabel = isUtilizationType() ? PortCounterAxisLabel.UTIL_AVE.getName()
            : PortCounterAxisLabel.COUNTS.getName();

    // setup the chart for the desired counter
    JFreeChart chart = ChartFactory.createTimeSeriesChart(getChartTitle(), "Time of Day", axisLabel, dataset1,
            true, true, false);

    if (isUtilizationType()) {
        chart.addSubtitle(new TextTitle(AnalysisType.getAnalysisName() + " (" + deltaPeriod + " sec. delta)"));
        //      chart.addSubtitle(new TextTitle("number of ports"));      
    } else
        chart.addSubtitle(new TextTitle(type.getName() + " Activity (" + deltaPeriod + " sec. delta)"));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.getRangeAxis().setFixedDimension(15.0);

    return chart;
}

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

/**
 * Creates a new demo.//  w w  w. ja va 2 s  .c om
 *
 * @param title the frame title.
 * @param pf
 */
public MessagesSent1(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Messages Sent");
    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, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Messages Sent " + 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("messagesnumber1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

/**
 * /* w w w .ja  v  a  2s. c  o  m*/
 */
public static Renderable evaluateRenderable(JasperReportsContext jasperReportsContext,
        JRComponentElement element, SpiderChartSharedBean spiderchartBean, ChartCustomizer chartCustomizer,
        String defaultRenderType, String datasetType) {
    SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
    ChartSettings chartSettings = chartComponent.getChartSettings();
    SpiderPlot plot = (SpiderPlot) chartComponent.getPlot();

    DefaultCategoryDataset dataset = null;
    StandardCategoryItemLabelGenerator labelGenerator = null;

    if (FILL_DATASET.equals(datasetType)) {
        dataset = ((FillSpiderDataset) spiderchartBean.getDataset()).getCustomDataset();
        labelGenerator = ((FillSpiderDataset) spiderchartBean.getDataset()).getLabelGenerator();
    } else {
        dataset = getSampleDataset();
        labelGenerator = new StandardCategoryItemLabelGenerator();
    }

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot(dataset);

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

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

    Font titleFont = chartSettings.getTitleFont() != null ? FontUtil.getInstance(jasperReportsContext)
            .getAwtFont(chartSettings.getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT;

    String titleText = spiderchartBean.getTitleText();

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

    Color backcolor = chartSettings.getBackcolor() != null ? chartSettings.getBackcolor()
            : element.getBackcolor();
    if (backcolor != null) {
        jfreechart.setBackgroundPaint(backcolor);
    }

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

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

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

    String subtitleText = spiderchartBean.getSubtitleText();
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (chartSettings.getSubtitleColor() != null) {
            subtitle.setPaint(chartSettings.getSubtitleColor());
        }

        if (chartSettings.getSubtitleColor() != null) {
            Font subtitleFont = chartSettings.getSubtitleFont() != null
                    ? FontUtil.getInstance(jasperReportsContext).getAwtFont(chartSettings.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 (chartSettings.getLegendColor() != null) {
                legend.setItemPaint(chartSettings.getLegendColor());
            }
            if (chartSettings.getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor());
            }

            if (chartSettings.getLegendFont() != null) {
                legend.setItemFont(FontUtil.getInstance(jasperReportsContext)
                        .getAwtFont(chartSettings.getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }

    String renderType = chartSettings.getRenderType() == null ? defaultRenderType
            : chartSettings.getRenderType();
    Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight());

    if (chartCustomizer != null) {
        chartCustomizer.customize(jfreechart, chartComponent);
    }

    return ChartUtil.getInstance(jasperReportsContext).getChartRenderableFactory(renderType)
            .getRenderable(jasperReportsContext, jfreechart, spiderchartBean.getHyperlinkProvider(), rectangle);
}

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

/**
 * Creates a new demo.//w w w .  j a va 2 s  . com
 *
 * @param title the frame title.
 * @param pf
 */
public InformationCollected1(final String title, ArrayList<Double> pf) {
    super(title);
    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);
    final CategoryAxis xAxis = new CategoryAxis("");
    final NumberAxis yAxis = new NumberAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    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, 14);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Information Collected " + 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("informationcollected1" + mazeMode + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformationCollected1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(InformationCollected1.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

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

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    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, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + 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("roundnumber1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    }

}