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

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

Introduction

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

Prototype

public void setItemFont(Font font) 

Source Link

Document

Sets the item font and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

@Override
public iPlatformComponent createChart(iPlatformComponent chartComponent, final ChartDefinition cd) {
    ChartInfo ci = (ChartInfo) cd.getChartHandlerInfo();

    if (ci != null) {
        ci.dispose();//from  w w  w .j  av a2s. c o  m
    }

    ci = new ChartInfo();
    cd.setChartHandlerInfo(ci);

    ChartPanelEx chartPanel = (ChartPanelEx) ((chartComponent == null) ? null : chartComponent.getView());

    if (chartPanel == null) {
        chartPanel = createChartPanel(null, cd);
        chartComponent = new Container(chartPanel);

        if (chartForeground != null) {
            chartComponent.setForeground(chartForeground);
        }

        if (chartFont != null) {
            chartComponent.setFont(chartFont);
        }

        if (chartBackground != null) {
            chartComponent.setBackground(chartBackground);
        }
    }

    ci.popularSeriesDataAndCaluclateRanges(this, cd);

    JFreeChart chart = createCharts(chartPanel, cd);

    chartPanel.setChart(chart);
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(null);
    chart.setBorderVisible(false);

    if (!cd.isAllowZooming()) {
        chartPanel.setRangeZoomable(false);
        chartPanel.setDomainZoomable(false);
    }

    ci.chart = chart;
    ChartHelper.setChartTitle(chart, cd.getTitle());

    if (cd.isShowLegends()) {
        LegendTitle l = new LegendTitle(chart.getPlot());

        l.setItemPaint(cd.getTextColor(legendLabelColor));
        l.setItemFont(cd.getTextFont(legendLabelFont));

        switch (cd.getLegendSide()) {
        case TOP:
            l.setPosition(RectangleEdge.TOP);

            break;

        case BOTTOM:
            l.setPosition(RectangleEdge.BOTTOM);

            break;

        case LEFT:
            l.setPosition(RectangleEdge.LEFT);

            break;

        default:
            l.setPosition(RectangleEdge.RIGHT);

            break;
        }

        chart.addSubtitle(l);
    }

    ChartFactory.getChartTheme().apply(chart);
    ((ChartInfo) cd.getChartHandlerInfo()).chartPanel = chartPanel;

    if ((cd.getSeriesCount() > 0) && (chartPanel.getHeight() > 0)) {
        chartPanel.updateTickmarks(chartPanel.getWidth(), chartPanel.getHeight());
    }

    return chartComponent;
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) {
    //       g2.setPaint(Color.white);
    //      g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    //      if (getChart() != null) {
    ////         Image chartImage = getChart().createBufferedImage((int) area.getWidth(),
    ////               (int) area.getHeight());
    ////         g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), 
    ////               this);
    //         getChart().draw(g2, area, getAnchor(), null);
    //         ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, 
    //               null, getChart());
    //      }/* w w w .j a v  a  2 s. c om*/
    double widthRatio = area.getWidth() / getWidth();
    double heightRatio = area.getHeight() / getHeight();
    double overallRatio = 1;
    overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio;

    XYPlot plot = (XYPlot) getChart().getPlot();
    Font domainFont = plot.getDomainAxis().getLabelFont();
    int domainSize = domainFont.getSize();
    Font rangeFont = plot.getRangeAxis().getLabelFont();
    int rangeSize = rangeFont.getSize();
    TextTitle titleBlock = getChart().getTitle();
    Font titleFont = null;
    int titleSize = 0;
    if (titleBlock != null) {
        titleFont = titleBlock.getFont();
        titleSize = titleFont.getSize();
        getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio)));
    }
    Font domainScaleFont = plot.getDomainAxis().getTickLabelFont();
    int domainScaleSize = domainScaleFont.getSize();
    Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont();
    int rangeScaleSize = rangeScaleFont.getSize();
    plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio)));
    plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio)));
    plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio)));
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio)));
    LegendTitle legend = getChart().getLegend();
    Font legendFont = null;
    int legendFontSize = 0;
    if (legend != null) {
        legendFont = legend.getItemFont();
        legendFontSize = legendFont.getSize();
        legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio)));
    }

    Rectangle2D chartArea = (Rectangle2D) area.clone();
    getChart().getPadding().trim(chartArea);
    if (titleBlock != null) {
        AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition());
    }

    Axis scaleAxis = null;
    Font scaleAxisFont = null;
    int scaleAxisFontSize = 0;
    for (Object object : getChart().getSubtitles()) {
        Title title = (Title) object;
        if (title instanceof PaintScaleLegend) {
            scaleAxis = ((PaintScaleLegend) title).getAxis();
            scaleAxisFont = scaleAxis.getTickLabelFont();
            scaleAxisFontSize = scaleAxisFont.getSize();
            scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio)));
        }
        AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition());
    }
    AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea);
    Rectangle2D dataArea = axisSpace.shrink(chartArea, null);
    getChart().getXYPlot().getInsets().trim(dataArea);
    getChart().getXYPlot().getAxisOffset().trim(dataArea);

    //        Rectangle2D screenArea = getScreenDataArea();
    //        Rectangle2D visibleArea = getVisibleRect();
    //        Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, 
    //              screenArea.getMinY() * overallRatio + y, 
    //              printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), 
    //              printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight());

    getChart().draw(g2, area, getAnchor(), null);
    ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio);
    ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart());
    ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart());
    plot.getDomainAxis().setLabelFont(domainFont);
    plot.getRangeAxis().setLabelFont(rangeFont);
    if (titleBlock != null) {
        titleBlock.setFont(titleFont);
    }
    if (legend != null) {
        legend.setItemFont(legendFont);
    }
    plot.getDomainAxis().setTickLabelFont(domainScaleFont);
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont);
    if (scaleAxis != null) {
        scaleAxis.setTickLabelFont(scaleAxisFont);
    }
    //        System.out.println("print " + titleBlock.getText() + 
    //              " at [" + area.getX() + ", " + area.getY() + ", " + 
    //              area.getWidth() + ", " + area.getHeight() + "]");
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *///ww w  .  java  2  s.  c  o m
protected void configureChart(JFreeChart jfreeChart) throws JRException {
    if (getChart().getModeValue() == ModeEnum.OPAQUE) {
        jfreeChart.setBackgroundPaint(getChart().getBackcolor());
    } else {
        jfreeChart.setBackgroundPaint(null);
    }

    RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP);

    if (jfreeChart.getTitle() != null) {
        TextTitle title = jfreeChart.getTitle();
        title.setPaint(getChart().getTitleColor());

        title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale()));
        title.setPosition(titleEdge);
    }

    String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setPaint(getChart().getSubtitleColor());

        subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale()));
        subtitle.setPosition(titleEdge);

        jfreeChart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        legend.setItemPaint(getChart().getLegendColor());

        if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless
        {
            legend.setBackgroundPaint(null);
        } else {
            legend.setBackgroundPaint(getChart().getLegendBackgroundColor());
        }

        legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale()));
        legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM));
    }

    configurePlot(jfreeChart.getPlot());
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart, Integer baseFontSize) {

    //The legend visibility is already taken into account in the jfreeChart object's constructor

    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        Font themeLegendFont = getFont(
                (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FONT),
                getChart().getLegendFont(), baseFontSize);
        legend.setItemFont(themeLegendFont);

        Color legendForecolor = getChart().getOwnLegendColor() != null ? getChart().getOwnLegendColor()
                : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) != null
                        ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                ChartThemesConstants.LEGEND_FORECOLOR)
                        : getChart().getLegendColor());
        if (legendForecolor != null)
            legend.setItemPaint(legendForecolor);

        Color legendBackcolor = getChart().getOwnLegendBackgroundColor() != null
                ? getChart().getOwnLegendBackgroundColor()
                : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) != null
                        ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                ChartThemesConstants.LEGEND_BACKCOLOR)
                        : getChart().getLegendBackgroundColor());
        if (legendBackcolor != null)
            legend.setBackgroundPaint(legendBackcolor);

        BlockFrame frame = (BlockFrame) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.LEGEND_FRAME);
        if (frame != null)
            legend.setFrame(frame);//from  ww w . ja v  a2  s.co  m

        HorizontalAlignment defaultLegendHAlignment = (HorizontalAlignment) getDefaultValue(
                defaultChartPropertiesMap, ChartThemesConstants.LEGEND_HORIZONTAL_ALIGNMENT);
        if (defaultLegendHAlignment != null)
            legend.setHorizontalAlignment(defaultLegendHAlignment);

        VerticalAlignment defaultLegendVAlignment = (VerticalAlignment) getDefaultValue(
                defaultChartPropertiesMap, ChartThemesConstants.LEGEND_VERTICAL_ALIGNMENT);
        if (defaultLegendVAlignment != null)
            legend.setVerticalAlignment(defaultLegendVAlignment);

        RectangleInsets defaultLegendPadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.LEGEND_PADDING);
        RectangleInsets legendPadding = legend.getPadding() != null ? legend.getPadding()
                : defaultLegendPadding;
        if (legendPadding != null)
            legend.setPadding(legendPadding);

        RectangleEdge defaultLegendPosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.LEGEND_POSITION);
        if (getEdge(getChart().getLegendPositionValue(), defaultLegendPosition) != null)
            legend.setPosition(getEdge(getChart().getLegendPositionValue(), defaultLegendPosition));

    }
}

From source file:userinterface.graph.Histogram.java

/**
 * Update the settings of the graph if the settings changed
 */// w w w .  j  a v  a2 s.  co  m
public void updateGraph() {

    /* Update title if necessary. */
    if (!this.chart.getTitle().equals(graphTitle)) {
        this.chart.setTitle(graphTitle.getStringValue());
    }

    /* Update title font if necessary. */
    if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) {
        this.chart.getTitle().setFont(titleFont.getFontColorValue().f);
    }

    /* Update title colour if necessary. */
    if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) {
        this.chart.getTitle().setPaint(titleFont.getFontColorValue().c);
    }

    if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) {
        if (!legendVisible.getBooleanValue()) {
            this.chart.removeLegend();
        } else {
            LegendTitle legend = new LegendTitle(plot.getRenderer());
            legend.setBackgroundPaint(Color.white);
            legend.setBorder(1, 1, 1, 1);

            this.chart.addLegend(legend);
        }
    }

    if (this.chart.getLegend() != null) {
        LegendTitle legend = this.chart.getLegend();

        /* Put legend on the left if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.LEFT)
                && !legend.getPosition().equals(RectangleEdge.LEFT)) {
            legend.setPosition(RectangleEdge.LEFT);
        }
        /* Put legend on the right if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.RIGHT)
                && !legend.getPosition().equals(RectangleEdge.RIGHT)) {
            legend.setPosition(RectangleEdge.RIGHT);
        }
        /* Put legend on the top if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.TOP)
                && !legend.getPosition().equals(RectangleEdge.TOP)) {
            legend.setPosition(RectangleEdge.TOP);
        }
        /* Put legend on the bottom if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.BOTTOM)
                && !legend.getPosition().equals(RectangleEdge.BOTTOM)) {
            legend.setPosition(RectangleEdge.BOTTOM);
        }

        /* Set legend font. */
        if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) {
            legend.setItemFont(legendFont.getFontColorValue().f);
        }
        /* Set legend font colour. */
        if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) {
            legend.setItemPaint(legendFont.getFontColorValue().c);
        }
    }

    super.repaint();
    doEnables();
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private LegendTitle createLegend(JFreeChart chart, UILegend legendcomp) {
    LegendTitle legend = new LegendTitle(chart.getPlot());

    PositionType position = legendcomp.getPosition();
    if (position == null) {
        legend.setPosition(RectangleEdge.BOTTOM);
    } else {//  w ww  .ja  v a  2  s  . co m
        setTitlePosition(legend, position);
    }

    Double tm = legendcomp.getTopMargin();
    Double lm = legendcomp.getLeftMargin();
    Double bm = legendcomp.getBottomMargin();
    Double rm = legendcomp.getRightMargin();
    if (tm == null)
        tm = 1.0;
    if (lm == null)
        lm = 1.0;
    if (bm == null)
        bm = 1.0;
    if (rm == null)
        rm = 1.0;
    legend.setMargin(new RectangleInsets(tm, lm, bm, rm));

    Paint bgcolor = legendcomp.getBackgroundColor();
    if (bgcolor != null) {
        legend.setBackgroundPaint(bgcolor);
    }

    Float borderWidth = legendcomp.getBorderWidth();
    Paint borderColor = legendcomp.getBorderColor();
    if (borderWidth != null || borderColor != null) {
        if (borderWidth == null)
            borderWidth = 1.0f;
        if (borderColor == null)
            borderColor = Color.black;
        LineBorder border = new LineBorder(borderColor, new BasicStroke(borderWidth),
                new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(border);
    }

    Font itemFont = legendcomp.getItemFont();
    Paint itemColor = legendcomp.getItemColor();
    if (itemFont != null)
        legend.setItemFont(itemFont);
    if (itemColor != null)
        legend.setItemPaint(itemColor);

    return legend;
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart) {
    //The legend visibility is already taken into account in the jfreeChart object's constructor
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        LegendSettings legendSettings = getLegendSettings();
        JRBaseFont font = new JRBaseFont();
        JRFontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
        JRFontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
        font = new JRBaseFont(getChart(), font);
        legend.setItemFont(JRFontUtil.getAwtFont(font, getLocale()));

        Paint forePaint = getChart().getOwnLegendColor();
        if (forePaint == null && legendSettings.getForegroundPaint() != null) {
            forePaint = legendSettings.getForegroundPaint().getPaint();
        }/*w ww  . j  av a2 s  . c o  m*/
        if (forePaint == null) {
            forePaint = getChart().getLegendColor();
        }
        if (forePaint != null)
            legend.setItemPaint(forePaint);

        Paint backPaint = getChart().getOwnLegendBackgroundColor();
        if (backPaint == null && legendSettings.getBackgroundPaint() != null) {
            backPaint = legendSettings.getBackgroundPaint().getPaint();
        }
        if (backPaint == null) {
            backPaint = getChart().getLegendBackgroundColor();
        }
        if (backPaint != null)
            legend.setBackgroundPaint(backPaint);

        BlockFrame blockFrame = legendSettings.getBlockFrame();
        if (blockFrame != null)
            legend.setFrame(blockFrame);

        HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
        if (hAlign != null)
            legend.setHorizontalAlignment(hAlign);

        VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
        if (vAlign != null)
            legend.setVerticalAlignment(vAlign);

        RectangleInsets padding = legendSettings.getPadding();
        if (padding != null)
            legend.setPadding(padding);

        legend.setPosition(getEdge(getChart().getLegendPositionValue(),
                getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM)));
    }
}

From source file:userinterface.graph.Graph.java

private void updateGraph() {
    /* Update title if necessary. */
    if (!this.chart.getTitle().equals(graphTitle)) {
        this.chart.setTitle(graphTitle.getStringValue());
    }/*from  www  .  j  a  va 2 s .c o  m*/

    /* Update title font if necessary. */
    if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) {
        this.chart.getTitle().setFont(titleFont.getFontColorValue().f);
    }

    /* Update title colour if necessary. */
    if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) {
        this.chart.getTitle().setPaint(titleFont.getFontColorValue().c);
    }

    if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) {
        if (!legendVisible.getBooleanValue()) {
            this.chart.removeLegend();
        } else {
            LegendTitle legend = new LegendTitle(plot.getRenderer());
            legend.setBackgroundPaint(Color.white);
            legend.setBorder(1, 1, 1, 1);

            this.chart.addLegend(legend);
        }
    }

    if (this.chart.getLegend() != null) {
        LegendTitle legend = this.chart.getLegend();

        /* Put legend on the left if appropriate. */
        if ((legendPosition.getCurrentIndex() == LEFT) && !legend.getPosition().equals(RectangleEdge.LEFT)) {
            legend.setPosition(RectangleEdge.LEFT);
        }
        /* Put legend on the right if appropriate. */
        if ((legendPosition.getCurrentIndex() == RIGHT) && !legend.getPosition().equals(RectangleEdge.RIGHT)) {
            legend.setPosition(RectangleEdge.RIGHT);
        }
        /* Put legend on the top if appropriate. */
        if ((legendPosition.getCurrentIndex() == TOP) && !legend.getPosition().equals(RectangleEdge.TOP)) {
            legend.setPosition(RectangleEdge.TOP);
        }
        /* Put legend on the bottom if appropriate. */
        if ((legendPosition.getCurrentIndex() == BOTTOM)
                && !legend.getPosition().equals(RectangleEdge.BOTTOM)) {
            legend.setPosition(RectangleEdge.BOTTOM);
        }

        /* Set legend font. */
        if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) {
            legend.setItemFont(legendFont.getFontColorValue().f);
        }
        /* Set legend font colour. */
        if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) {
            legend.setItemPaint(legendFont.getFontColorValue().c);
        }
    }

    super.repaint();
    doEnables();
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart) {
    //The legend visibility is already taken into account in the jfreeChart object's constructor
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        LegendSettings legendSettings = getLegendSettings();
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
        FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
        font = new JRBaseFont(getChart(), font);
        legend.setItemFont(getFontUtil().getAwtFont(font, getLocale()));

        Paint forePaint = getChart().getOwnLegendColor();
        if (forePaint == null && legendSettings.getForegroundPaint() != null) {
            forePaint = legendSettings.getForegroundPaint().getPaint();
        }/*  w w  w .ja  va2 s.c  o  m*/
        if (forePaint == null) {
            forePaint = getChart().getLegendColor();
        }
        if (forePaint != null)
            legend.setItemPaint(forePaint);

        Paint backPaint = getChart().getOwnLegendBackgroundColor();
        if (backPaint == null && legendSettings.getBackgroundPaint() != null) {
            backPaint = legendSettings.getBackgroundPaint().getPaint();
        }
        if (backPaint == null) {
            backPaint = getChart().getLegendBackgroundColor();
        }
        if (backPaint != null)
            legend.setBackgroundPaint(backPaint);

        BlockFrame blockFrame = legendSettings.getBlockFrame();
        if (blockFrame != null)
            legend.setFrame(blockFrame);

        HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
        if (hAlign != null)
            legend.setHorizontalAlignment(hAlign);

        VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
        if (vAlign != null)
            legend.setVerticalAlignment(vAlign);

        RectangleInsets padding = legendSettings.getPadding();
        if (padding != null)
            legend.setPadding(padding);

        legend.setPosition(getEdge(getChart().getLegendPositionValue(),
                getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM)));
    }
}

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 w  ww .ja v a2s  . 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);
}