Example usage for org.jfree.chart LegendItem setLabelFont

List of usage examples for org.jfree.chart LegendItem setLabelFont

Introduction

In this page you can find the example usage for org.jfree.chart LegendItem setLabelFont.

Prototype

public void setLabelFont(Font font) 

Source Link

Document

Sets the label font.

Usage

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private LegendItem createLegendItem(int dataSetIndex, int series, XYDataset dataSet) {

    Shape shape = lookupLegendShape(series);
    Paint fillPaint = (getUseFillPaint() ? lookupSeriesFillPaint(series) : lookupSeriesPaint(series));
    Paint outlinePaint = (getUseOutlinePaint() ? lookupSeriesOutlinePaint(series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    Paint labelPaint = lookupLegendTextPaint(series);
    Font labelFont = lookupLegendTextFont(series);

    String itemLegendLabel = getLegendItemLabelGenerator().generateLabel(dataSet, series);
    final XYSeriesLabelGenerator toolTipGenerator = getLegendItemToolTipGenerator();
    String toolTipText = (toolTipGenerator != null) ? toolTipGenerator.generateLabel(dataSet, series) : null;
    final XYSeriesLabelGenerator urlGenerator = getLegendItemURLGenerator();
    String urlText = urlGenerator != null ? urlGenerator.generateLabel(dataSet, series) : null;

    boolean isItemShapeVisible = getItemShapeVisible(series, 0);
    boolean isItemShapeFilled = getItemShapeFilled(series, 0);
    boolean isItemShapeOutlineVisible = getDrawOutlines();
    boolean isItemLineVisible = getItemLineVisible(series, 0);

    LegendItem legendItem = new LegendItem(itemLegendLabel, itemLegendLabel, toolTipText, urlText,
            isItemShapeVisible, shape, isItemShapeFilled, fillPaint, isItemShapeOutlineVisible, outlinePaint,
            outlineStroke, isItemLineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), lineStroke, linePaint);

    legendItem.setLabelFont(labelFont);
    legendItem.setLabelPaint(labelPaint);
    legendItem.setSeriesKey(dataSet.getSeriesKey(series));
    legendItem.setSeriesIndex(series);// w w w.  j ava  2 s . c  o m
    legendItem.setDataset(dataSet);
    legendItem.setDatasetIndex(dataSetIndex);

    return legendItem;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

/**
 * Creates a title item (i.e. bold font etc.) with the given string. Simply gets the default
 * font from the plotConfig and sets it style to bold.
 * /*from   ww w. ja va 2 s. c o m*/
 * @return The created legend item.
 */
private LegendItem createTitleLegendItem(String titleString, PlotConfiguration plotConfiguration) {
    LegendItem titleItem = new LegendItem(titleString, "", "", "", false, new Rectangle(), false, Color.WHITE,
            false, Color.WHITE, new BasicStroke(), false, new Rectangle(), new BasicStroke(), Color.WHITE);
    Font titleFont = titleItem.getLabelFont();

    if (titleFont == null) {
        titleFont = plotConfiguration.getLegendConfiguration().getLegendFont();
    }
    titleItem.setLabelFont(titleFont.deriveFont(Font.BOLD));
    return titleItem;
}

From source file:org.trade.ui.chart.renderer.PivotRenderer.java

/**
 * Returns a legend item for the specified series.
 * //from   w  w w.  j a  v a  2 s.  com
 * @param datasetIndex
 *            the dataset index (zero-based).
 * @param series
 *            the series index (zero-based).
 * 
 * 
 * @return A legend item for the series (possibly <code>null</code>). * @see
 *         org.jfree.chart.renderer.xy.XYItemRenderer#getLegendItem(int,
 *         int)
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

    // if the renderer isn't assigned to a plot, then we don't have a
    // dataset...
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    LegendItem result = null;
    if (getItemVisible(series, 0)) {
        String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
        String description = label;
        String toolTipText = null;
        if (getLegendItemToolTipGenerator() != null) {
            toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
        }
        String urlText = null;
        if (getLegendItemURLGenerator() != null) {
            urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
        }
        Paint fillPaint = lookupSeriesPaint(series);
        result = new LegendItem(label, description, toolTipText, urlText, getLegendShape(), fillPaint);
        result.setLabelFont(lookupLegendTextFont(series));
        Paint labelPaint = lookupLegendTextPaint(series);
        if (labelPaint != null) {
            result.setLabelPaint(labelPaint);
        }
        result.setSeriesKey(dataset.getSeriesKey(series));
        result.setSeriesIndex(series);
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
    }

    return result;

}

From source file:KIDLYRenderer.java

/**
 * Returns a legend item for a series./*  w  ww. jav a2s  . c o m*/
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item (possibly <code>null</code>).
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }

    CategoryDataset dataset = cp.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);

    LegendItem result = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint,
            isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f),
            Color.black);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);
    result.setSeriesKey(dataset.getRowKey(series));
    result.setSeriesIndex(series);
    if (this.gradientPaintTransformer != null) {
        result.setFillPaintTransformer(this.gradientPaintTransformer);
    }
    return result;
}

From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java

/**
 * Returns a legend item for a series.//  www  .  j a v a  2  s  .  c  o m
 *
 * @param datasetIndex
 *            the dataset index (zero-based).
 * @param series
 *            the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(final int datasetIndex, final int series) {
    final XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }
    LegendItem result = null;
    final XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset != null) {
        if (getItemVisible(series, 0)) {
            final String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
            final String description = label;
            String toolTipText = null;
            if (getLegendItemToolTipGenerator() != null) {
                toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
            }
            String urlText = null;
            if (getLegendItemURLGenerator() != null) {
                urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
            }
            final Shape shape = lookupLegendShape(series);
            final boolean shapeFilled = getItemShapeFilled(series, 0);
            final Paint paint = lookupSeriesPaint(series);
            final Paint linePaint = paint;
            final Stroke lineStroke = lookupSeriesStroke(series);
            result = new LegendItem(label, description, toolTipText, urlText, this.baseShapesVisible, shape,
                    shapeFilled, paint, !shapeFilled, paint, lineStroke, this.plotLines, this.legendLine,
                    lineStroke, linePaint);
            result.setLabelFont(lookupLegendTextFont(series));
            final Paint labelPaint = lookupLegendTextPaint(series);
            if (labelPaint != null) {
                result.setLabelPaint(labelPaint);
            }
            result.setDataset(dataset);
            result.setDatasetIndex(datasetIndex);
            result.setSeriesKey(dataset.getSeriesKey(series));
            result.setSeriesIndex(series);
        }
    }
    return result;
}

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/** process the lines */
private final void __processLines() {
    final LegendItemCollection legendCollection;
    final boolean addLegend;
    final ChartPalette palette;
    Stroke legendStroke;/*w ww.j  ava 2  s  . c o m*/
    Color legendColor;
    int index;
    Line2D line;
    List<Line2D> lines;
    Iterator<Point2D> it;
    Point2D p;
    boolean foreground;
    XYSeries ser;
    String name;
    LegendItem item;

    lines = this.getBackgroundLines();
    ((_JFCXYLineAndShapeRenderer) (this.m_plot.getDrawingSupplier())).m_backgroundCount = lines.size();
    foreground = false;

    legendCollection = new LegendItemCollection();
    addLegend = (this.getLegendType() != ELegendType.NO_LEGEND);
    palette = this.getDriver().getPalette();

    // first add all foreground lines, than all background lines
    outer: for (;;) {
        index = 0;

        while (lines.size() > 0) {
            line = lines.remove(0);
            it = this.iterateLinePoints(line);

            // // are there any points to plot?
            // if (it.hasNext()) {
            // // then let's make a series and plot them!
            name = line.name();
            ser = new XYSeries(((name != null) ? name : EmptyUtils.EMPTY_STRING), false, true);

            while (it.hasNext()) {
                p = it.next();
                ser.add(_JFCLineChart2D.__format(p.getX()), _JFCLineChart2D.__format(p.getY()));
            }

            this.m_dataset.addSeries(ser);

            if (addLegend && (name != null) && (name.length() > 0)) {

                legendColor = (foreground ? //
                        palette.getForegroundDataColor(index)//
                        : palette.getBackgroundDataColor(index));
                legendStroke = (foreground ? //
                        palette.getForegroundDataStroke(index)//
                        : palette.getBackgroundDataStroke(index));

                item = new LegendItem(//
                        name, null, null, null, // text
                        false, _JFCLineChart2D.EMPTY_SHAPE, false, // shape
                        legendColor, //
                        false, //
                        legendColor, //
                        legendStroke, //
                        false, _JFCLineChart2D.EMPTY_SHAPE, // line
                        legendStroke, //
                        legendColor//
                );
                item.setLabelFont(palette.getLegendFont());
                item.setLabelPaint(legendColor);
                legendCollection.add(item);
            }
            index++;
            // }
        }

        if (foreground) {
            break outer;
        }
        foreground = true;
        lines = this.getLines();
    }

    this.m_plot.setFixedLegendItems(legendCollection);
}