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

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

Introduction

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

Prototype

public void setPosition(RectangleEdge position) 

Source Link

Document

Sets the position for the title and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:org.gumtree.vis.core.internal.SWTChartComposite.java

private void setLegend(String legendPosition) {
    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        if (legendPosition.equals(LEGEND_BOTTOM_COMMAND)) {
            legend.setVisible(true);//w  ww .  j ava  2 s .  c  o m
            legend.setPosition(RectangleEdge.BOTTOM);
        } else if (legendPosition.equals(LEGEND_RIGHT_COMMAND)) {
            legend.setVisible(true);
            legend.setPosition(RectangleEdge.RIGHT);
        } else
            legend.setVisible(false);
    }
}

From source file:com.rapidminer.gui.plotter.charts.WebPlotter.java

@Override
public void updatePlotter() {
    final int categoryCount = prepareData();

    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from w w  w.j  a  v  a2 s. co m*/
        public void run() {
            scrollablePlotterPanel.remove(viewScrollBar);
        }
    });

    if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                viewScrollBar.setOrientation(Adjustable.HORIZONTAL);
                scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH);
            }
        });

        this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT);
        viewScrollBar.setMaximum(categoryCount);
        viewScrollBar.setValue(0);

    } else {
        this.slidingCategoryDataSet = null;
    }

    if (categoryCount <= MAX_CATEGORIES) {

        SpiderWebPlot plot = new SpiderWebPlot(categoryDataSet);

        plot.setAxisLinePaint(Color.LIGHT_GRAY);
        plot.setOutlinePaint(Color.WHITE);

        plot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

        JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, true);

        double[] colorValues = null;
        if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) {
            colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)];
        } else {
            colorValues = new double[categoryDataSet.getColumnCount()];
        }
        for (int i = 0; i < colorValues.length; i++) {
            colorValues[i] = i;
        }

        if (panel != null) {
            panel.setChart(chart);
        } else {
            panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
            scrollablePlotterPanel.add(panel, BorderLayout.CENTER);
            final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
            panel.addMouseListener(controller);
            panel.addMouseMotionListener(controller);
        }

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }
        if (groupByColumn < 0) {
            // no legend is needed when there is no group-by selection
            chart.removeLegend();
        }
        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private LegendTitle createLegend(final Collection<VehicleRoute> routes, final XYSeriesCollection shipments,
        final XYPlot plot) {
    LegendItemSource lis = new LegendItemSource() {

        @Override/*  w  w w.  ja  va2  s  .  c o  m*/
        public LegendItemCollection getLegendItems() {
            LegendItemCollection lic = new LegendItemCollection();
            LegendItem vehLoc = new LegendItem("vehLoc", Color.RED);
            vehLoc.setShape(ELLIPSE);
            vehLoc.setShapeVisible(true);
            lic.add(vehLoc);
            if (containsServiceAct) {
                LegendItem item = new LegendItem("service", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsPickupAct) {
                LegendItem item = new LegendItem("pickup", Color.GREEN);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsDeliveryAct) {
                LegendItem item = new LegendItem("delivery", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (routes != null) {
                LegendItem item = new LegendItem("firstActivity", Color.BLACK);
                Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f);
                item.setShape(upTriangle);
                item.setOutlinePaint(Color.BLACK);

                item.setLine(upTriangle);
                item.setLinePaint(Color.BLACK);
                item.setShapeVisible(true);

                lic.add(item);
            }
            if (!shipments.getSeries().isEmpty()) {
                lic.add(plot.getRenderer(1).getLegendItem(1, 0));
            }
            if (routes != null) {
                lic.addAll(plot.getRenderer(2).getLegendItems());
            }
            return lic;
        }
    };

    LegendTitle legend = new LegendTitle(lis);
    legend.setPosition(RectangleEdge.BOTTOM);
    return legend;
}

From source file:jspritTest.util.Plotter.java

private LegendTitle createLegend(final Collection<VehicleRoute> routes, final XYSeriesCollection shipments,
        final XYPlot plot) {
    LegendItemSource lis = new LegendItemSource() {

        public LegendItemCollection getLegendItems() {
            LegendItemCollection lic = new LegendItemCollection();
            LegendItem vehLoc = new LegendItem("vehLoc", Color.RED);
            vehLoc.setShape(ELLIPSE);/* w  w w  . j av a2  s . c om*/
            vehLoc.setShapeVisible(true);
            lic.add(vehLoc);
            if (containsServiceAct) {
                LegendItem item = new LegendItem("service", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsPickupAct) {
                LegendItem item = new LegendItem("pickup", Color.GREEN);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsDeliveryAct) {
                LegendItem item = new LegendItem("delivery", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (routes != null) {
                LegendItem item = new LegendItem("firstActivity", Color.BLACK);
                Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f);
                item.setShape(upTriangle);
                item.setOutlinePaint(Color.BLACK);

                item.setLine(upTriangle);
                item.setLinePaint(Color.BLACK);
                item.setShapeVisible(true);

                lic.add(item);
            }
            if (!shipments.getSeries().isEmpty()) {
                lic.add(plot.getRenderer(1).getLegendItem(1, 0));
            }
            if (routes != null) {
                lic.addAll(plot.getRenderer(2).getLegendItems());
            }
            return lic;
        }
    };

    LegendTitle legend = new LegendTitle(lis);
    legend.setPosition(RectangleEdge.BOTTOM);
    return legend;
}

From source file:com.rapidminer.gui.plotter.charts.ParetoChartPlotter.java

public void paintParetoChart(Graphics graphics) {
    prepareData();/*from w  w  w  .j av  a  2s  . c  om*/

    JFreeChart chart = createChart();

    if (chart != null) {
        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);
        chart.getPlot().setBackgroundPaint(Color.WHITE);

        // bar renderer --> own 3D effect
        CategoryPlot plot = chart.getCategoryPlot();
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        // renderer.setBarPainter(new StandardBarPainter());
        renderer.setBarPainter(new RapidBarPainter());

        renderer.setSeriesPaint(0, getColorProvider(true).getPointColor(1));

        // labels on top of bars
        Map<String, String> barItemLabels = new HashMap<>();
        Map<String, String> cumulativeItemLabels = new HashMap<>();
        int groupSum = 0;
        int totalSum = 0;
        for (Object key : totalData.getKeys()) {
            String k = (String) key;
            try {
                Number groupValue = data.getValue(k);
                Number totalValue = totalData.getValue(k);
                groupSum += groupValue.intValue();
                totalSum += totalValue.intValue();
                barItemLabels.put(k, Tools.formatIntegerIfPossible(groupValue.doubleValue()) + " / "
                        + Tools.formatIntegerIfPossible(totalValue.doubleValue()));
                cumulativeItemLabels.put(k, groupSum + " / " + totalSum);
            } catch (UnknownKeyException e) {
                // do nothing
            }
        }
        renderer.setSeriesItemLabelFont(0, LABEL_FONT);

        if (showBarLabelsFlag) {
            renderer.setSeriesItemLabelsVisible(0, true);
            renderer.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(barItemLabels));

            if (isLabelRotating()) {
                renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                        TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
                renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                        TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
            }
        }

        LineAndShapeRenderer renderer2 = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(1);
        renderer2.setSeriesPaint(0, Color.GRAY.darker().darker());
        renderer2.setSeriesItemLabelFont(0, LABEL_FONT);
        renderer2.setSeriesItemLabelPaint(0, Color.BLACK);
        if (isLabelRotating()) {
            renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
            renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
        } else {
            renderer2.setSeriesPositiveItemLabelPosition(0,
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT));
            renderer2.setSeriesNegativeItemLabelPosition(0,
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT));
        }

        if (showCumulativeLabelsFlag) {
            renderer2.setSeriesItemLabelsVisible(0, true);
            renderer2.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(cumulativeItemLabels));
        }

        // draw outlines
        renderer.setDrawBarOutline(true);

        // gridline colors
        plot.setRangeGridlinePaint(Color.BLACK);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }

        Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
        chart.draw((Graphics2D) graphics, drawRect);
    }
}

From source file:org.tiefaces.components.websheet.chart.ChartHelper.java

/**
 * finalize the style for jfreechart. The default setting is different from
 * jfreechart and Excel. We try to minimize the difference.
 * /* w w  w  .j  a va  2  s .  c om*/
 * @param chart
 *            jfreechart.
 * @param chartData
 *            contain information gathered from excel chart object.
 */

private void setupStyle(final JFreeChart chart, final ChartData chartData) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    List<ChartSeries> seriesList = chartData.getSeriesList();
    BasicStroke bLine = new BasicStroke(2.0f);
    for (int i = 0; i < seriesList.size(); i++) {
        Color cColor = ColorUtility.xssfClrToClr(seriesList.get(i).getSeriesColor().getXssfColor());
        plot.getRenderer().setSeriesPaint(i, cColor);
        plot.getRenderer().setSeriesStroke(i, bLine);
    }
    plot.setBackgroundPaint(ColorUtility.xssfClrToClr(chartData.getBgColor().getXssfColor()));

    // below are modifications for default setting in excel chart
    // to-do: need read setting from xml in future
    plot.setOutlineVisible(false);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setRangeGridlineStroke(new BasicStroke(TieConstants.DEFAULT_BASIC_STROKE));
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    chart.setBackgroundPaint(Color.WHITE);
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setFrame(BlockBorder.NONE);

}

From source file:com.rapidminer.gui.plotter.charts.DistributionPlotter.java

@Override
public void updatePlotter() {

    JFreeChart chart = null;//from   w ww.j av a  2 s.  c o  m
    Attribute attr = null;
    if (plotColumn != -1 && createFromModel) {
        attr = model.getTrainingHeader().getAttributes().get(model.getAttributeNames()[plotColumn]);
    }
    if (attr != null && attr.isNominal()
            && attr.getMapping().getValues().size() > MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES) {
        // showing no chart because of too many different values
        chart = new JFreeChart(new Plot() {

            private static final long serialVersionUID = 1L;

            @Override
            public String getPlotType() {
                return "empty";
            }

            @Override
            public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
                    PlotRenderingInfo info) {
                String msg = I18N.getGUILabel("plotter_panel.too_many_nominals", "Distribution Plotter",
                        DistributionPlotter.MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES);
                g2.setColor(Color.BLACK);
                g2.setFont(g2.getFont().deriveFont(g2.getFont().getSize() * 1.35f));
                g2.drawChars(msg.toCharArray(), 0, msg.length(), 50, (int) (area.getHeight() / 2 + 0.5d));
            }
        });
        AbstractChartPanel panel = getPlotterPanel();
        // Chart Panel Settings
        if (panel == null) {
            panel = createPanel(chart);
        } else {
            panel.setChart(chart);
        }
        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        preparePlots();

        if (!createFromModel && (groupColumn < 0 || plotColumn < 0)) {
            CategoryDataset dataset = new DefaultCategoryDataset();
            chart = ChartFactory.createBarChart(null, // chart title
                    "Not defined", // x axis label
                    RANGE_AXIS_NAME, // y axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
            );
        } else {
            try {
                if (model.isDiscrete(translateToModelColumn(plotColumn))) {
                    chart = createNominalChart();
                } else {
                    chart = createNumericalChart();
                }
            } catch (Exception e) {
                // do nothing - just do not draw the chart
            }
        }

        if (chart != null) {
            chart.setBackgroundPaint(Color.white);

            // get a reference to the plot for further customization...
            Plot commonPlot = chart.getPlot();
            commonPlot.setBackgroundPaint(Color.WHITE);
            if (commonPlot instanceof XYPlot) {
                XYPlot plot = (XYPlot) commonPlot;

                plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
                plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

                // domain axis
                if (dataTable != null) {
                    if (dataTable.isDate(plotColumn) || dataTable.isDateTime(plotColumn)) {
                        DateAxis domainAxis = new DateAxis(dataTable.getColumnName(plotColumn));
                        domainAxis.setTimeZone(com.rapidminer.tools.Tools.getPreferredTimeZone());
                        plot.setDomainAxis(domainAxis);
                    } else {
                        NumberAxis numberAxis = new NumberAxis(dataTable.getColumnName(plotColumn));
                        plot.setDomainAxis(numberAxis);
                    }
                }

                plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

                plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

                // ranging
                if (dataTable != null) {
                    Range range = getRangeForDimension(plotColumn);
                    if (range != null) {
                        plot.getDomainAxis().setRange(range, true, false);
                    }

                    range = getRangeForName(RANGE_AXIS_NAME);
                    if (range != null) {
                        plot.getRangeAxis().setRange(range, true, false);
                    }
                }

                // rotate labels
                if (isLabelRotating()) {
                    plot.getDomainAxis().setTickLabelsVisible(true);
                    plot.getDomainAxis().setVerticalTickLabels(true);
                }

            } else if (commonPlot instanceof CategoryPlot) {
                CategoryPlot plot = (CategoryPlot) commonPlot;

                plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
                plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

                plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

                plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getDomainAxis().setTickLabelFont(LABEL_FONT);
            }

            // legend settings
            LegendTitle legend = chart.getLegend();
            if (legend != null) {
                legend.setPosition(RectangleEdge.TOP);
                legend.setFrame(BlockBorder.NONE);
                legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
                legend.setItemFont(LABEL_FONT);
            }

            AbstractChartPanel panel = getPlotterPanel();
            // Chart Panel Settings
            if (panel == null) {
                panel = createPanel(chart);
            } else {
                panel.setChart(chart);
            }

            // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
            panel.getChartRenderingInfo().setEntityCollection(null);
        }
    }
}

From source file:org.tiefaces.components.websheet.chart.ChartHelper.java

/**
 * finalize the style for jfreechart. The default setting is different from
 * jfreechart and Excel. We try to minimize the difference.
 * /*ww w.ja  va  2 s  .c o m*/
 * @param chart
 *            jfreechart.
 * @param chartData
 *            contain information gathered from excel chart object.
 */

private void setupPieStyle(final JFreeChart chart, final ChartData chartData) {
    PiePlot plot = (PiePlot) chart.getPlot();
    List<ChartSeries> seriesList = chartData.getSeriesList();
    List<ParsedCell> categoryList = chartData.getCategoryList();
    BasicStroke bLine = new BasicStroke(2.0f);
    for (int i = 0; i < seriesList.size(); i++) {
        ChartSeries chartSeries = seriesList.get(i);
        List<XColor> valueColorList = chartSeries.getValueColorList();
        for (int index = 0; index < categoryList.size(); index++) {
            try {
                String sCategory = getParsedCellValue(categoryList.get(index));
                Color cColor = ColorUtility.xssfClrToClr(valueColorList.get(index).getXssfColor());
                plot.setSectionPaint(sCategory, cColor);
                plot.setSectionOutlineStroke(sCategory, bLine);
            } catch (Exception ex) {
                LOG.log(Level.FINE, "SetupPieStyle error = " + ex.getLocalizedMessage(), ex);
            }
        }

    }
    plot.setBackgroundPaint(ColorUtility.xssfClrToClr(chartData.getBgColor().getXssfColor()));

    // below are modifications for default setting in excel chart
    // to-do: need read setting from xml in future

    plot.setOutlineVisible(false);
    plot.setLegendItemShape(new Rectangle(TieConstants.DEFAULT_LEGENT_ITEM_SHAPE_WIDTH,
            TieConstants.DEFAULT_LEGENT_ITEM_SHAPE_HEIGHT));
    chart.setBackgroundPaint(Color.WHITE);
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setFrame(BlockBorder.NONE);

}

From source file:com.polivoto.vistas.Charts.java

private JPanel hacerPiePanel(Pregunta pregunta, List<Opcion> opciones) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(Color.white);
    DefaultPieDataset data = new DefaultPieDataset();
    // Fuente de Datos
    for (Opcion opc : opciones) {
        data.setValue(opc.getNombre(), opc.getCantidad());
    }//from   www .  jav  a2 s .c om

    // Creando el Grafico
    JFreeChart chart = ChartFactory.createPieChart("\n" + pregunta.getTitulo(), data, true, false, //TOOLTIPS
            false);
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Roboto", 0, 28));

    // Crear el Panel del Grafico con ChartPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();

    Rectangle bounds = panel.getBounds();
    chartPanel.setBounds(bounds.x, bounds.y, bounds.height, bounds.height);

    panel.add(chartPanel);

    plot.setLabelGenerator(null);
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineVisible(false);
    //StandardPieSectionLabelGenerator labels = new StandardPieSectionLabelGenerator("{0} = {1}");
    //plot.setLabelGenerator(labels);

    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //#7cb5ec,#f45b5b,#90ed7d,#434348,
    //#f7a35c,#8085e9,#f15c80,#e4d354,
    //#2b908f,#91e8e1
    Color[] colors = { new Color(124, 181, 236), new Color(244, 91, 91), new Color(144, 237, 125),
            new Color(67, 67, 72), new Color(247, 163, 92), new Color(128, 133, 233), new Color(241, 92, 128),
            new Color(228, 211, 84), new Color(43, 144, 143), new Color(145, 232, 225) };
    PieRenderer renderer = new PieRenderer(colors);
    renderer.setColor(plot, data);

    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    Font nwfont = new Font("Roboto", 0, 18);
    legend.setItemFont(nwfont);
    legend.setFrame(new BlockBorder(0, 0, 0, 90, Color.white));
    legend.setBackgroundPaint(Color.WHITE);
    legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 0));
    //RectangleInsets padding = new RectangleInsets(5, 5, 5, 5);
    //legend.setItemLabelPadding(padding);
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}"));
    plot.setLegendItemShape(new Rectangle(25, 25));
    return panel;
}

From source file:org.ash.gui.StackedChart.java

/**
 * Creates the chart./*ww  w. j a v  a 2s  .  co m*/
 * 
 * @return the j free chart
 */
private JFreeChart createChart() {

    xAxis = new DateAxis("time");
    xAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));

    currentDate = new Date();
    updatexAxisLabel(new Long(currentDate.getTime()).doubleValue());

    chart = ChartFactory.createStackedXYAreaChart("Top activity", // chart title
            "X Value", // domain axis label
            "Active Sessions", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            xAxis, false, // legend
            true, // tooltips
            false // urls
    );

    plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer3 renderer = new StackedXYAreaRenderer3();
    renderer.setRoundXCoordinates(true);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})",
            new SimpleDateFormat("HH:mm"), new DecimalFormat("0.0")));
    plot.setRenderer(0, renderer);
    plot.getRangeAxis().setLowerBound(0.0);
    plot.getRangeAxis().setAutoRange(true);

    // add a labelled marker for the cpu_count
    thresholdMaxCpu = new ValueMarker(this.maxCpu);
    thresholdMaxCpu.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    thresholdMaxCpu.setPaint(Color.red);
    thresholdMaxCpu.setStroke(new BasicStroke(1.0f));
    thresholdMaxCpu.setLabel("Maximum CPU");
    thresholdMaxCpu.setLabelFont(new Font("SansSerif", Font.PLAIN, 11));
    thresholdMaxCpu.setLabelPaint(Color.red);
    thresholdMaxCpu.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    thresholdMaxCpu.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
    plot.addRangeMarker(thresholdMaxCpu);

    renderer.setSeriesPaint(0,
            Options.getInstance().getColor(Options.getInstance().getResource("cpuLabel.text")), true);
    renderer.setSeriesPaint(1,
            Options.getInstance().getColor(Options.getInstance().getResource("schedulerLabel.text")), true);
    renderer.setSeriesPaint(2,
            Options.getInstance().getColor(Options.getInstance().getResource("userIOLabel.text")), true);
    renderer.setSeriesPaint(3,
            Options.getInstance().getColor(Options.getInstance().getResource("systemIOLabel.text")), true);
    renderer.setSeriesPaint(4,
            Options.getInstance().getColor(Options.getInstance().getResource("concurrencyLabel.text")), true);
    renderer.setSeriesPaint(5,
            Options.getInstance().getColor(Options.getInstance().getResource("applicationsLabel.text")), true);
    renderer.setSeriesPaint(6,
            Options.getInstance().getColor(Options.getInstance().getResource("commitLabel.text")), true);
    renderer.setSeriesPaint(7,
            Options.getInstance().getColor(Options.getInstance().getResource("configurationLabel.text")), true);
    renderer.setSeriesPaint(8,
            Options.getInstance().getColor(Options.getInstance().getResource("administrativeLabel.text")),
            true);
    renderer.setSeriesPaint(9,
            Options.getInstance().getColor(Options.getInstance().getResource("networkLabel.text")), true);
    renderer.setSeriesPaint(11,
            Options.getInstance().getColor(Options.getInstance().getResource("queueningLabel.text")), true);//que
    renderer.setSeriesPaint(10,
            Options.getInstance().getColor(Options.getInstance().getResource("clusterLabel.text")), true);//cluster
    renderer.setSeriesPaint(12,
            Options.getInstance().getColor(Options.getInstance().getResource("otherLabel.text")), true);

    // Set format for x axis
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    // Add legend to right
    LegendTitle legend = new LegendTitle(chart.getPlot());

    BlockContainer wrapper = new BlockContainer(new BorderArrangement());
    wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0));

    BlockContainer itemss = legend.getItemContainer();
    itemss.setPadding(2, 10, 5, 2);
    wrapper.add(itemss);
    legend.setWrapper(wrapper);

    legend.setPosition(RectangleEdge.RIGHT);
    legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

    chart.addSubtitle(legend);

    return chart;
}