Example usage for org.jfree.chart JFreeChart setPadding

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

Introduction

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

Prototype

public void setPadding(RectangleInsets padding) 

Source Link

Document

Sets the padding between the chart border and the chart drawing area, and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:ec.ui.view.AutoCorrelationsView.java

private static JFreeChart createAutoCorrelationsViewChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);
    result.setPadding(TsCharts.CHART_PADDING);

    XYPlot plot = result.getXYPlot();//from w ww .  j  ava2s.  com

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(true);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setAutoPopulateSeriesOutlinePaint(false);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}

From source file:org.gbif.portal.web.util.ChartUtils.java

/**
 * Writes out the image using the supplied file name.
 * /*from  w  ww . j ava  2s.  c o m*/
 * @param legend
 * @param fileName
 * @return
 */
public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) {

    String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension;
    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName + defaultExtension;
    }

    final DefaultPieDataset data = new DefaultPieDataset();
    Set<String> keys = legend.keySet();
    for (String key : keys) {
        logger.info("Adding key : " + key);
        data.setValue(key, legend.get(key));
    }

    // create a pie chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false);

    PiePlot piePlot = (PiePlot) chart.getPlot();
    piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    piePlot.setLabelBackgroundPaint(Color.WHITE);

    LegendTitle lt = chart.getLegend();
    lt.setBackgroundPaint(Color.WHITE);
    lt.setWidth(300);
    lt.setBorder(0, 0, 0, 0);
    lt.setItemFont(new Font("Arial", Font.PLAIN, 11));

    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250);

    // draw
    chart.draw(g2, chartArea, null, null);

    try {
        FileOutputStream fOut = new FileOutputStream(fileToCheck);
        ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250);
        return fileToCheck.getName();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Lead pipeline.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the leads in the system for now.
 */// www  .j  a  va  2 s.  co m
public static String createLeadPipelineChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all LEAD statuses that are not CONVERTED, or DEAD
    List<GenericValue> leadStatuses = ReportHelper.findLeadStatusesForDashboardReporting(delegator);

    // report number of leads for each status
    for (GenericValue status : leadStatuses) {
        String statusId = status.getString("statusId");
        long count = delegator.findCountByCondition("PartyAndStatus",
                EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null);
        dataset.addValue(count, "", (String) status.get("description", locale));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmLeadPipeline"), null, null,
            dataset, PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(227, 246, 206), 0.0f, 0.0f,
            new Color(153, 204, 102));
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 200, null);
}

From source file:com.opensourcestrategies.financials.reports.JFreeFinancialCharts.java

/**
 * Liquidity snapshot chart.  Documentation is at http://www.opentaps.org/docs/index.php/Financials_Home_Screen
 *
 * Because a user might not have permission to view balances in all areas, this method takes into consideration
 * the ability to view various bars in the chart.
 *
 * @param accountsMap Map of accounts keyed by the glAccountType
 * @return String filename pointing to the chart, to be used with showChart URI request
 *///from   www  .  j  av a  2  s  .co  m
public static String createLiquiditySnapshotChart(Map<String, GenericValue> accountsMap,
        List<GenericValue> creditCardAccounts, Locale locale, boolean hasReceivablesPermission,
        boolean hasPayablesPermission, boolean hasInventoryPermission)
        throws GenericEntityException, IOException {
    Map<String, Object> uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // compile the four bars
    if (hasReceivablesPermission) {
        double cashBalance = 0.0;
        cashBalance += getPostedBalance(accountsMap.get("UNDEPOSITED_RECEIPTS"));
        cashBalance += getPostedBalance(accountsMap.get("BANK_STLMNT_ACCOUNT"));
        dataset.addValue(cashBalance, "", (String) uiLabelMap.get("FinancialsCashEquivalents"));

        double receivablesBalance = 0.0;
        receivablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_RECEIVABLE"));
        // merchant account settlement balances are receivable
        receivablesBalance += getPostedBalance(accountsMap.get("MRCH_STLMNT_ACCOUNT"));
        dataset.addValue(receivablesBalance, "", (String) uiLabelMap.get("FinancialsReceivables"));
    }
    if (hasInventoryPermission) {
        double inventoryBalance = 0.0;
        inventoryBalance += getPostedBalance(accountsMap.get("INVENTORY_ACCOUNT"));
        inventoryBalance += getPostedBalance(accountsMap.get("RAWMAT_INVENTORY"));
        inventoryBalance += getPostedBalance(accountsMap.get("WIP_INVENTORY"));
        dataset.addValue(inventoryBalance, "", (String) uiLabelMap.get("WarehouseInventory"));
    }
    if (hasPayablesPermission) {
        double payablesBalance = 0.0;
        payablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_PAYABLE"));
        payablesBalance += getPostedBalance(accountsMap.get("COMMISSIONS_PAYABLE"));
        payablesBalance += getPostedBalance(accountsMap.get("UNINVOICED_SHIP_RCPT"));
        dataset.addValue(payablesBalance, "", (String) uiLabelMap.get("FinancialsPayables"));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("FinancialsLiquiditySnapshot"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GRAY);
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // tilt the category labels so they fit
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 400, 300, null);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private static JFreeChart createTsChart() {
    XYPlot plot = new XYPlot();

    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setLowerMargin(0.02);//w w  w .j a  v a2 s.c o m
    domainAxis.setUpperMargin(0.02);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setLowerMargin(0.02);
    rangeAxis.setUpperMargin(0.02);
    plot.setRangeAxis(rangeAxis);

    JFreeChart result = new JFreeChart("", null, plot, true);
    result.setPadding(new RectangleInsets(5, 5, 5, 5));
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);

    return result;
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Opportunities by stage.  Description at
 * http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the opportunities in the system for now.
 *///from w ww  .  j a  v a2 s  .  c o m
public static String createOpportunitiesbyStageChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String currency = UtilConfig.getPropertyValue("crmsfa", "defaultCurrencyUomId");

    // get all sales opportunity stages that are not closed, or lost
    List<GenericValue> salesOpportunityStages = ReportHelper
            .findSalesOpportunityStagesForDashboardReporting(delegator);

    // report number of leads for each status
    for (GenericValue stage : salesOpportunityStages) {
        String opportunityStageId = stage.getString("opportunityStageId");
        EntityCondition conditions = EntityCondition.makeCondition(EntityOperator.AND,
                EntityCondition.makeCondition("opportunityStageId", EntityOperator.EQUALS, opportunityStageId),
                EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, currency));
        List<GenericValue> salesOpportunityEstimatedAmountTotals = delegator
                .findByConditionCache("SalesOpportunityEstimatedAmountTotalByStage", conditions, null, null);

        if (salesOpportunityEstimatedAmountTotals != null && !salesOpportunityEstimatedAmountTotals.isEmpty()) {
            GenericValue salesOpportunityEstimatedAmountTotal = salesOpportunityEstimatedAmountTotals.get(0);
            dataset.addValue(salesOpportunityEstimatedAmountTotal.getDouble("estimatedAmountTotal"), "",
                    (String) stage.get("description", locale));
        } else {
            dataset.addValue(0, "", (String) stage.get("description", locale));
        }
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart(
            (String) UtilMessage.expandLabel("CrmOpportunitiesbyStage", locale,
                    UtilMisc.toMap("currency", currency)),
            null, null, dataset, PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(206, 246, 245), 0.0f, 0.0f,
            new Color(51, 204, 204));
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 200, null);
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Open Cases snapshot.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the cases in the system for now.
 *//*from  w  w  w  .  j  a  v  a  2s .c om*/
public static String createOpenCasesChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all case statuses that are not "closed" (this is dynamic because statuses may be added at run time)
    List<GenericValue> statuses = ReportHelper.findCasesStagesForDashboardReporting(delegator);

    // Report number of cases for each status
    for (GenericValue status : statuses) {
        String statusId = status.getString("statusId");
        long count = delegator.findCountByCondition("CustRequest",
                EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null);
        dataset.addValue(count, "", (String) status.get("description", locale));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmOpenCases"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(246, 227, 206), 0.0f, 0.0f,
            new Color(204, 153, 102));
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // tilt the category labels so they fit
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 300, null);
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Team Member Activity Snapshot.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the team members in the system for now.
 *///  w  w w  .  j a  v  a 2 s .c o  m
public static String createActivitiesByTeamMemberChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all team members (read the TODO in this function)
    List<GenericValue> teamMembers = TeamHelper.getTeamMembersForOrganization(delegator);

    // condition to count activities
    EntityCondition conditions = EntityCondition.makeCondition(EntityOperator.AND,
            EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PRTYASGN_ASSIGNED"),
            EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_IN,
                    UtilActivity.ACT_STATUSES_COMPLETED),
            EntityUtil.getFilterByDateExpr());

    // condition to count pending outbound emails
    EntityCondition commConditions = EntityCondition.makeCondition(EntityOperator.AND,
            EntityCondition.makeCondition("communicationEventTypeId", EntityOperator.EQUALS,
                    "EMAIL_COMMUNICATION"),
            EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "TASK"),
            EntityCondition.makeCondition("workEffortPurposeTypeId", EntityOperator.EQUALS, "WEPT_TASK_EMAIL"),
            EntityCondition.makeCondition("currentStatusId", EntityOperator.IN,
                    UtilMisc.toList("TASK_SCHEDULED", "TASK_STARTED")),
            EntityCondition.makeCondition("assignmentStatusId", EntityOperator.EQUALS, "PRTYASGN_ASSIGNED"),
            EntityUtil.getFilterByDateExpr());

    // count active work efforts for each team member
    for (GenericValue member : teamMembers) {
        String partyId = member.getString("partyId");
        EntityCondition memberCond = EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId);
        long count = delegator.findCountByCondition("WorkEffortAndPartyAssign", memberCond, null);

        // subtract outbound emails
        EntityCondition commCond = EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId);
        count -= delegator.findCountByCondition("WorkEffortPartyAssignCommEvent", commCond, null);

        // bar will be the name of the team member
        StringBuffer name = new StringBuffer();
        name.append(member.get("lastName")).append(", ").append(member.get("firstName"));
        dataset.addValue(count, "", name.toString());
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmActivitiesByTeamMember"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(230, 230, 230), 0.0f, 0.0f,
            new Color(153, 153, 153));
    renderer.setSeriesPaint(0, gp);

    // by default the gradient is vertical, but we can make it horizontal like this
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // save as a png and return the file name (vertical height depends on size of team members)
    return ServletUtilities.saveChartAsPNG(chart, 360, 100 + 25 * teamMembers.size(), null);
}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Creates a chart that displays multiple 3D pie plots that have a GradientPaintTransformer.  
 * The chart object returned by this method uses a {@link MultiplePiePlot} instance as the plot.
 *
 * @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?//  w  ww.  j  a v a  2 s . co  m
 * @param tooltips  generate tooltips?
 * @param urls  generate URLs?
 *
 * @return A chart.
 */
private static JFreeChart createPieChart(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 PiePlot3DGradient(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 10));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.getTitle().setPadding(0, 0, 0, 0);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    pieChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    pieChart.getPlot().setInsets(new RectangleInsets(0, 0, 0, 0));
    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:presentation.webgui.vitroappservlet.StyleCreator.java

private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors,
        Model3dStylesEntry givStyleEntry) {
    String capSimpleName = givStyleEntry.getCorrCapability();
    capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, "");
    JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);/*from   w  ww . java  2  s  .c  o m*/

    chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14));
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white); // seen
    CategoryPlot plot = chart.getCategoryPlot();
    chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new

    plot.setNoDataMessage("NO DATA!");

    Paint[] tmpPaintCategories = { Color.white };
    if (givCategColors.size() > 0) {
        tmpPaintCategories = new Paint[givCategColors.size()];
        for (int i = 0; i < givCategColors.size(); i++) {
            tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i));
        }
    }

    CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories);

    renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new

    plot.setRenderer(renderer);

    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new
    plot.setForegroundAlpha(1f); //new
    plot.setBackgroundAlpha(1f); //new
    plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0
    plot.setRangeGridlinesVisible(false); //new was true
    plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray);
    plot.setOutlinePaint(Color.white);

    //plot.setOrientation(PlotOrientation.HORIZONTAL);

    CategoryAxis domainAxis = plot.getDomainAxis();

    domainAxis.setLowerMargin(0.04);
    domainAxis.setUpperMargin(0.04);
    domainAxis.setVisible(true);
    domainAxis.setLabelAngle(Math.PI / 2);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0); // new: was 100
    rangeAxis.setVisible(false);
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}