Example usage for org.jfree.chart LegendItem setLabelPaint

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

Introduction

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

Prototype

public void setLabelPaint(Paint paint) 

Source Link

Document

Sets the paint used to draw the label.

Usage

From source file:com.xilinx.kintex7.PowerDial.java

public void createDial() {
    plot = new MeterPlot();
    dset = new DefaultValueDataset(0);
    plot.setUnits("Watts");
    plot.setRange(new Range(1, 10));
    plot.addInterval(new MeterInterval("Acceptable", new Range(1.0, 6.0), Color.lightGray,
            new BasicStroke(2.0f), Color.GREEN));
    plot.addInterval(new MeterInterval("Warning", new Range(6.0, 8.0), Color.lightGray, new BasicStroke(2.0f),
            Color.YELLOW));/*from   ww w .  j  a v  a  2  s .c  o m*/
    plot.addInterval(new MeterInterval("Dangerous", new Range(8.0, 10.0), Color.lightGray,
            new BasicStroke(2.0f), Color.RED));

    //sets different marks
    for (int i = 0; i < 10; i += 1) {
        if (i == 0)
            plot.addInterval(
                    new MeterInterval("", new Range(1, 1), Color.lightGray, new BasicStroke(2.0f), null));
        else
            plot.addInterval(
                    new MeterInterval("", new Range(i, i), Color.lightGray, new BasicStroke(2.0f), null));
    }
    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.PIE);
    plot.setMeterAngle(180);
    plot.setTickLabelsVisible(true);
    plot.setTickLabelFont(new Font("Dialog", Font.BOLD, 10));
    plot.setTickLabelPaint(Color.DARK_GRAY);
    plot.setTickSize(10.0);
    plot.setTickPaint(Color.lightGray);
    plot.setValuePaint(Color.BLACK);
    plot.setDataset(dset);

    LegendItemCollection legendItemsOld = plot.getLegendItems();
    final LegendItemCollection legendItemsNew = new LegendItemCollection();

    for (int i = 0; i < 3; i++) {
        LegendItem item = legendItemsOld.get(i);
        item.setLabelPaint(Color.WHITE);
        legendItemsNew.add(item);
    }

    LegendItemSource source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(legendItemsNew);
        }

        @Override
        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };

    chart = new JFreeChart(plot);
    chart.addLegend(new LegendTitle(source));
    chart.removeLegend();
    chart.setTitle("");
    //chart.setBackgroundPaint(new GradientPaint(0,0,new Color(139,137,137),0,height,Color.BLUE ));
    //
    chart.getTitle().setPaint(Color.white);
    plot.setValueFont(new Font("Dialog", Font.BOLD, 14));
    //chartpanel = new ChartPanel(chart);
}

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);// www.  jav a2  s  .c o  m
    legendItem.setLabelPaint(labelPaint);
    legendItem.setSeriesKey(dataSet.getSeriesKey(series));
    legendItem.setSeriesIndex(series);
    legendItem.setDataset(dataSet);
    legendItem.setDatasetIndex(dataSetIndex);

    return legendItem;
}

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

/**
 * Returns a legend item for the specified series.
 * /*  w  w w.java  2s . co m*/
 * @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  w  w. j  a v a2  s . 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./*from  www. j a v  a  2  s.  co 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;/*from  w  w  w  .  j a  v  a 2 s  .co 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);
}