Example usage for org.jfree.chart.title LegendTitle setMargin

List of usage examples for org.jfree.chart.title LegendTitle setMargin

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setMargin.

Prototype

public void setMargin(RectangleInsets margin) 

Source Link

Document

Sets the margin (use RectangleInsets#ZERO_INSETS for no padding).

Usage

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private void setLegend(JFreeChart chart, boolean bShowLegend, Font font, Color foregroundColor,
        Color backgroundColor, cfCHARTLEGENDData legendData) throws cfmRunTimeException {
    LegendTitle legend = new LegendTitle(chart.getPlot());
    legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));

    // If a CFCHARTLEGEND tag was used then use it's attributes to configure the
    // legend//from ww w . j  a v  a  2s  .co m
    if (legendData != null) {
        // A CFCHARTLEGEND tag is present so use its attributes to configure the
        // legend
        legend.setItemFont(getFont(legendData.getFont(), legendData.getFontBold(), legendData.getFontItalic(),
                legendData.getFontSize()));
        legend.setItemPaint(convertStringToColor(legendData.getLabelColor()));
        legend.setBackgroundPaint(convertStringToColor(legendData.getBackgroundColor()));

        String pos = legendData.getPosition();
        if (pos.equals("top"))
            legend.setPosition(RectangleEdge.TOP);
        else if (pos.equals("bottom"))
            legend.setPosition(RectangleEdge.BOTTOM);
        else if (pos.equals("left"))
            legend.setPosition(RectangleEdge.LEFT);
        else if (pos.equals("right"))
            legend.setPosition(RectangleEdge.RIGHT);

        if (!legendData.getShowBorder())
            legend.setBorder(BlockBorder.NONE);
        else
            legend.setBorder(new BlockBorder());
    } else {
        // A CFCHARTLEGEND tag is NOT present so use the attributes from the
        // CFCHART tag to configure the legend
        if (!bShowLegend)
            return;

        legend.setItemFont(font);
        legend.setItemPaint(foregroundColor);
        legend.setBackgroundPaint(backgroundColor);

        // By default CFMX 7 places the legend at the top with no border
        legend.setPosition(RectangleEdge.TOP);
        legend.setBorder(BlockBorder.NONE);
    }

    // Add the legend to the chart
    chart.addSubtitle(legend);
}