Example usage for org.jfree.chart JFreeChart getLegend

List of usage examples for org.jfree.chart JFreeChart getLegend

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getLegend.

Prototype

public LegendTitle getLegend() 

Source Link

Document

Returns the legend for the chart, if there is one.

Usage

From source file:net.sourceforge.processdash.ev.ui.EVReport.java

/** Create a time series chart. */
public JFreeChart createChart() {
    JFreeChart chart = AbstractEVTimeSeriesChart.createEVReportChart(xydata);
    if (parameters.get("hideLegend") == null)
        chart.getLegend().setPosition(RectangleEdge.RIGHT);
    return chart;
}

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   w ww.j  a  va2s . co  m

    // 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.pentaho.chart.plugin.jfreechart.chart.JFreeChartGenerator.java

public JFreeChart createChart(ChartDocumentContext chartDocContext, ChartTableModel data) {
    JFreeChart chart = doCreateChart(chartDocContext, data);

    chart.setBackgroundPaint(getChartBackgroundColor(chartDocContext.getChartDocument()));

    Color chartBackgroundPaint = ColorFactory.getInstance()
            .getColor(chartDocContext.getChartDocument().getPlotElement(), BorderStyleKeys.BACKGROUND_COLOR);
    if (chartBackgroundPaint != null) {
        chart.getPlot().setBackgroundPaint(chartBackgroundPaint);
    }/*from  w  w w  .  ja  v  a  2s.c  o m*/

    CSSNumericValue opacity = (CSSNumericValue) chartDocContext.getChartDocument().getPlotElement()
            .getLayoutStyle().getValue(ColorStyleKeys.OPACITY);
    if (opacity != null) {
        chart.getPlot().setForegroundAlpha((float) opacity.getValue());
    }

    ChartElement rootElement = chartDocContext.getChartDocument().getRootElement();
    ChartElement[] children = rootElement.findChildrenByName(ChartElement.TAG_NAME_TITLE); //$NON-NLS-1$
    if (children != null && children.length > 0) {
        Font font = ChartUtils.getFont(children[0]);
        if (font != null) {
            chart.getTitle().setFont(font);
        }
    }

    if (getShowLegend(chartDocContext.getChartDocument())) {
        children = chartDocContext.getChartDocument().getRootElement()
                .findChildrenByName(ChartElement.TAG_NAME_LEGEND); //$NON-NLS-1$
        if ((children != null) && (children.length > 0)) {
            ChartElement legendElement = children[0];
            Font font = JFreeChartUtils.getFont(legendElement);
            if (font != null) {
                chart.getLegend().setItemFont(font);
            }

            CSSNumericValue value = (CSSNumericValue) legendElement.getLayoutStyle()
                    .getValue(BorderStyleKeys.BORDER_TOP_WIDTH);
            if ((value == null) || (value.getValue() <= 0)) {
                chart.getLegend().setBorder(BlockBorder.NONE);
            }
        }
    }

    CSSValue borderWidth = rootElement.getLayoutStyle().getValue(BorderStyleKeys.BORDER_TOP_WIDTH);
    if ((borderWidth != null) && (borderWidth instanceof CSSNumericValue)
            && (((CSSNumericValue) borderWidth).getValue() > 0)) {
        chart.setBorderVisible(true);
    } else if ((borderWidth != null) && (borderWidth instanceof CSSStringValue)) {
        chart.setBorderVisible(true);
    }

    Color borderColor = ColorFactory.getInstance().getColor(rootElement, BorderStyleKeys.BORDER_TOP_COLOR);
    if (borderColor != null) {
        chart.setBorderPaint(borderColor);
    }

    Plot plot = chart.getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;

        children = chartDocContext.getChartDocument().getRootElement()
                .findChildrenByName(ChartElement.TAG_NAME_RANGE_LABEL); //$NON-NLS-1$
        if (children != null && children.length > 0) {
            Font font = ChartUtils.getFont(children[0]);
            if (font != null) {
                categoryPlot.getRangeAxis().setLabelFont(font);
            }
        }

        children = chartDocContext.getChartDocument().getRootElement()
                .findChildrenByName(ChartElement.TAG_NAME_DOMAIN_LABEL); //$NON-NLS-1$
        if (children != null && children.length > 0) {
            Font font = ChartUtils.getFont(children[0]);
            if (font != null) {
                categoryPlot.getDomainAxis().setLabelFont(font);
            }
        }
    }
    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java

protected void configureChart(final JFreeChart chart) {
    // Misc Properties
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        final Font titleFont = Font.decode(getTitleFont());
        chartTitle.setFont(titleFont);/*  w  w  w  . j  a  v  a  2 s  . c  o  m*/
    }

    if (isAntiAlias() == false) {
        chart.setAntiAlias(false);
    }

    chart.setBorderVisible(isShowBorder());

    final Color backgroundColor = parseColorFromString(getBackgroundColor());
    if (backgroundColor != null) {
        chart.setBackgroundPaint(backgroundColor);
    }

    if (plotBackgroundColor != null) {
        chart.getPlot().setBackgroundPaint(plotBackgroundColor);
    }
    chart.getPlot().setBackgroundAlpha(plotBackgroundAlpha);
    chart.getPlot().setForegroundAlpha(plotForegroundAlpha);
    final Color borderCol = parseColorFromString(getBorderColor());
    if (borderCol != null) {
        chart.setBorderPaint(borderCol);
    }

    //remove legend if showLegend = false
    if (!isShowLegend()) {
        chart.removeLegend();
    } else { //if true format legend
        final LegendTitle chLegend = chart.getLegend();
        if (chLegend != null) {
            final RectangleEdge loc = translateEdge(legendLocation.toLowerCase());
            if (loc != null) {
                chLegend.setPosition(loc);
            }
            if (getLegendFont() != null) {
                chLegend.setItemFont(Font.decode(getLegendFont()));
            }
            if (!isDrawLegendBorder()) {
                chLegend.setBorder(BlockBorder.NONE);
            }
            if (legendBackgroundColor != null) {
                chLegend.setBackgroundPaint(legendBackgroundColor);
            }
            if (legendTextColor != null) {
                chLegend.setItemPaint(legendTextColor);
            }
        }

    }

    final Plot plot = chart.getPlot();
    plot.setNoDataMessageFont(Font.decode(getLabelFont()));

    final String message = getNoDataMessage();
    if (message != null) {
        plot.setNoDataMessage(message);
    }

    plot.setOutlineVisible(isChartSectionOutline());

    if (backgroundImage != null) {
        if (plotImageCache != null) {
            plot.setBackgroundImage(plotImageCache);
        } else {
            final ExpressionRuntime expressionRuntime = getRuntime();
            final ProcessingContext context = expressionRuntime.getProcessingContext();
            final ResourceKey contentBase = context.getContentBase();
            final ResourceManager manager = context.getResourceManager();
            try {
                final ResourceKey key = createKeyFromString(manager, contentBase, backgroundImage);
                final Resource resource = manager.create(key, null, Image.class);
                final Image image = (Image) resource.getResource();
                plot.setBackgroundImage(image);
                plotImageCache = image;
            } catch (Exception e) {
                logger.error("ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e); //$NON-NLS-1$
                throw new IllegalStateException("Failed to process chart");
            }
        }
    }
}

From source file:mil.tatrc.physiology.utilities.csv.plots.ConvexHullPlotter.java

protected void formatConvexHullPlot(PlotJob job, JFreeChart chart, XYSeriesCollection dataSet1,
        XYSeriesCollection dataSet2) {//from   w  w  w.  j  ava  2 s  .c om
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(2.0f);

    //For Scientific notation
    NumberFormat formatter = new DecimalFormat("0.######E0");

    for (int i = 0; i < plot.getDomainAxisCount(); i++) {
        plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
        plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15));
        plot.getDomainAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
        plot.getDomainAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
    }
    for (int i = 0; i < plot.getRangeAxisCount(); i++) {
        plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
        plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15));
        plot.getRangeAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
        plot.getRangeAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i);
        rangeAxis.setNumberFormatOverride(formatter);
    }

    //White background outside of plottable area
    chart.setBackgroundPaint(job.bgColor);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15));
    chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
    chart.getTitle().setPaint(job.bgColor == Color.red ? Color.white : Color.black);

    //If there is only one Y axis, color all datasets red (so top, bottom, left, and right will be the same)
    if (job.Y2headers == null || job.Y2headers.isEmpty()) {
        for (int i = 0; i < dataSet1.getSeriesCount(); i++) {
            renderer1.setSeriesStroke(i, wideLine);
            renderer1.setBaseShapesVisible(false);
            renderer1.setSeriesFillPaint(i, Color.red);
            renderer1.setSeriesPaint(i, Color.red);
            if (dataSet1.getSeries(i).getKey() != null
                    && dataSet1.getSeries(i).getKey().toString().equalsIgnoreCase("REMOVE"))
                renderer1.setSeriesVisibleInLegend(i, false);
        }
    }
    //If there are 2 Y axes, we should color the axes to correspond with the data so it isn't (as) confusing
    else {
        StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
        plot.setRenderer(1, renderer2);

        for (int i = 0; i < dataSet1.getSeriesCount(); i++) {
            renderer1.setSeriesStroke(i, wideLine);
            renderer1.setBaseShapesVisible(false);
            renderer1.setSeriesFillPaint(i, Color.red);
            renderer1.setSeriesPaint(i, Color.red);
            if (dataSet1.getSeries(i).getKey() != null
                    && dataSet1.getSeries(i).getKey().toString().equalsIgnoreCase("REMOVE"))
                renderer1.setSeriesVisibleInLegend(i, false);
        }
        for (int i = 0; i < dataSet2.getSeriesCount(); i++) {
            renderer2.setSeriesStroke(i, wideLine);
            renderer2.setBaseShapesVisible(false);
            renderer2.setSeriesFillPaint(i, Color.blue);
            renderer2.setSeriesPaint(i, Color.blue);
            if (dataSet2.getSeries(i).getKey() != null
                    && dataSet2.getSeries(i).getKey().toString().equalsIgnoreCase("REMOVE"))
                renderer2.setSeriesVisibleInLegend(i, false);
        }
        plot.getRangeAxis(0).setLabelPaint(Color.red);
        plot.getRangeAxis(0).setTickLabelPaint(Color.red);
        plot.getRangeAxis(1).setLabelPaint(Color.blue);
        plot.getRangeAxis(1).setTickLabelPaint(Color.blue);
    }
}

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.  jav  a2  s. com
 * @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.rapidminer.gui.plotter.charts.MultipleScatterPlotter.java

@Override
public void updatePlotter() {

    prepareData();/*  w w w  .j  a v a 2 s .com*/

    JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // URLs
    );

    if (xAxis >= 0) {
        int size = dataSet.getSeriesCount();
        chart = ChartFactory.createScatterPlot(null, // chart title
                null, // domain axis label
                null, // range axis label
                dataSet, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // URLs
        );

        // renderer settings
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
        renderer.setBaseOutlinePaint(Color.BLACK);
        renderer.setUseOutlinePaint(true);
        renderer.setDrawOutlines(true);

        for (int i = 0; i < size; i++) {
            renderer.setSeriesShapesVisible(i, this.showPoints[plotIndexToColumnIndexMap.get(i)]);
            renderer.setSeriesLinesVisible(i, this.showLines[plotIndexToColumnIndexMap.get(i)]);
        }

        renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7));

        // 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);
        }
    }

    // GENERAL CHART SETTINGS

    int size = dataSet.getSeriesCount();
    if (size <= 1) {
        chart.getXYPlot().getRenderer().setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else {
        for (int i = 0; i < dataSet.getSeriesCount(); i++) {
            chart.getXYPlot().getRenderer().setSeriesStroke(i,
                    new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            chart.getXYPlot().getRenderer().setSeriesPaint(i,
                    getColorProvider().getPointColor(i / (double) (dataSet.getSeriesCount() - 1)));
        }
    }

    // set the background colors for the chart...
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(false);

    // general plot settings
    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    if (xAxis >= 0) {
        if (dataTable.isNominal(xAxis)) {
            String[] values = new String[dataTable.getNumberOfValues(xAxis)];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(xAxis, i);
            }
            plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(xAxis), values));
        } else if ((dataTable.isDate(xAxis)) || (dataTable.isDateTime(xAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(xAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setDomainAxis(domainAxis);
        } else {
            if (xLogScale) {
                LogAxis domainAxis = new LogAxis(dataTable.getColumnName(xAxis));
                domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
                plot.setDomainAxis(domainAxis);
            } else {
                NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(xAxis));
                domainAxis.setAutoRangeStickyZero(false);
                domainAxis.setAutoRangeIncludesZero(false);
                plot.setDomainAxis(domainAxis);
            }
        }
    }
    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

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

    // range axis
    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

    // Chart Panel Settings
    if (panel instanceof AbstractChartPanel) {
        panel.setChart(chart);
    } else {
        panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);

        final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
        panel.addMouseListener(controller);
        panel.addMouseMotionListener(controller);

        // react to mouse clicks
        // ATTENTION: ACTIVATING THIS WILL LEAD TO SEVERE MEMORY LEAKS!!! (see below)
        panel.addChartMouseListener(new ChartMouseListener() {

            @Override
            public void chartMouseClicked(ChartMouseEvent e) {
                if (e.getTrigger().getClickCount() > 1) {
                    XYItemEntity entity = (XYItemEntity) e.getEntity();
                    if (entity != null) {
                        String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem()));
                        if (id != null) {
                            ObjectVisualizer visualizer = ObjectVisualizerService
                                    .getVisualizerForObject(dataTable);
                            visualizer.startVisualization(id);
                        }
                    }
                }
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent e) {
            }
        });
    }

    // tooltips
    class CustomXYToolTipGenerator implements XYToolTipGenerator {

        public CustomXYToolTipGenerator() {
        }

        @Override
        public String generateToolTip(XYDataset dataset, int row, int column) {
            String id = idMap.get(new SeriesAndItem(row, column));
            if (id != null) {
                return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>";
            } else {
                return "<html>(" + dataset.getSeriesKey(row) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>";
            }
        }
    }

    for (int i = 0; i < dataSet.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator());
    }
}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java

public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1,
        String protocol2) {/*w w w .j ava  2s  . c om*/
    // ?
    XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1);
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();

    XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer();
    // ??1?1

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D);
    // ???

    // ??
    xylineandshaperenderer1.setSeriesLinesVisible(0, true);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F));

    // ?
    XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2);
    /*      XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10,
    Double.parseDouble(abnor.getElementAt(10).getData()));
          xyplot.addAnnotation(localXYTextAnnotation);*/
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    int datasetcount = xyplot.getDatasetCount();
    xyplot.setDataset(datasetcount, xydataset2);
    xyplot.setRenderer(datasetcount, xylineandshaperenderer2);
    /*      System.out.println("DatasetCount="+xyplot.getDatasetCount());
                  
          for(int c=0;c<xyplot.getDatasetCount();c++){
             System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount());
             System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0));
          }*/

    /*   // ??? 
       xylineandshaperenderer2.setBaseShapesVisible(false);
       // ??
       xylineandshaperenderer2.setSeriesLinesVisible(0, true);
       xylineandshaperenderer2.setSeriesShape(0, double1);
       // 
       xylineandshaperenderer2.setSeriesPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesFillPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
            
       xylineandshaperenderer2.setUseFillPaint(true);
       xylineandshaperenderer2
    .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
       xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
               
    */
    xylineandshaperenderer2.setSeriesLinesVisible(0, true);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
    xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
    jfreechart.getLegend().setVisible(true);
    return jfreechart;

}

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

@Override
protected void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {// w  ww .j  ava2s. com
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Series plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
        // LogService.WARNING);
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.plotter.charts.SeriesChartPlotter.parsing_property_error");
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    JFreeChart chart = createChart(this.dataset, createLegend);

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

    // domain axis
    if (axis[INDEX] >= 0) {
        if (!dataTable.isNominal(axis[INDEX])) {
            if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) {
                DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX]));
                domainAxis.setTimeZone(Tools.getPreferredTimeZone());
                chart.getXYPlot().setDomainAxis(domainAxis);
                if (getRangeForDimension(axis[INDEX]) != null) {
                    domainAxis.setRange(getRangeForDimension(axis[INDEX]));
                }
                domainAxis.setLabelFont(LABEL_FONT_BOLD);
                domainAxis.setTickLabelFont(LABEL_FONT);
                domainAxis.setVerticalTickLabels(isLabelRotating());
            }
        } else {
            LinkedHashSet<String> values = new LinkedHashSet<String>();
            for (DataTableRow row : dataTable) {
                String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX]));
                if (stringValue.length() > 40) {
                    stringValue = stringValue.substring(0, 40);
                }
                values.add(stringValue);
            }
            ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]),
                    values.toArray(new String[values.size()]));
            categoryAxis.setLabelFont(LABEL_FONT_BOLD);
            categoryAxis.setTickLabelFont(LABEL_FONT);
            categoryAxis.setVerticalTickLabels(isLabelRotating());
            chart.getXYPlot().setDomainAxis(categoryAxis);
        }
    }

    // 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();
    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:com.rapidminer.gui.plotter.charts.BubbleChartPlotter.java

@Override
public void updatePlotter() {
    final DataTable dataTable = getDataTable();

    prepareData();//from ww  w. j a  v  a2  s . co m

    JFreeChart chart = ChartFactory.createBubbleChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            xyzDataSet, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // URLs
    );

    if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0 && axis[BUBBLE_SIZE_AXIS] >= 0) {
        if (nominal) {
            int size = xyzDataSet.getSeriesCount();
            chart = ChartFactory.createBubbleChart(null, // chart title
                    null, // domain axis label
                    null, // range axis label
                    xyzDataSet, // data
                    PlotOrientation.VERTICAL, // orientation
                    colorColumn >= 0 && size < 100 ? true : false, // include legend
                    true, // tooltips
                    false // URLs
            );

            // renderer settings
            XYBubbleRenderer renderer = (XYBubbleRenderer) chart.getXYPlot().getRenderer();
            renderer.setBaseOutlinePaint(Color.BLACK);

            if (size > 1) {
                for (int i = 0; i < size; i++) {
                    renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1)));
                    renderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 7, 7));
                }
            } else {
                renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
                renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7));
            }

            // 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);
            }
        } else {
            chart = ChartFactory.createScatterPlot(null, // chart title
                    null, // domain axis label
                    null, // range axis label
                    xyzDataSet, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // URLs
            );

            // renderer settings
            ColorizedBubbleRenderer renderer = new ColorizedBubbleRenderer(this.colors);
            renderer.setBaseOutlinePaint(Color.BLACK);
            chart.getXYPlot().setRenderer(renderer);

            // legend settings
            chart.addLegend(new LegendTitle(renderer) {

                private static final long serialVersionUID = 1288380309936848376L;

                @Override
                public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area,
                        java.lang.Object params) {
                    if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn)
                            || dataTable.isDateTime(colorColumn)) {
                        drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7),
                                dataTable, colorColumn, minColor, maxColor);
                        return new BlockResult();
                    } else {
                        final String minColorString = Tools.formatNumber(minColor);
                        final String maxColorString = Tools.formatNumber(maxColor);
                        drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90),
                                (int) (area.getCenterY() + 7), dataTable.getColumnName(colorColumn),
                                minColorString, maxColorString);
                        return new BlockResult();
                    }
                }

                @Override
                public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) {
                    draw(g2, area, null);
                }

            });
        }
    }

    // GENERAL CHART SETTINGS

    // set the background colors for the chart...
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.getPlot().setForegroundAlpha(0.7f);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    if (axis[X_AXIS] >= 0) {
        if (dataTable.isNominal(axis[X_AXIS])) {
            String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(axis[X_AXIS], i);
            }
            plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values));
        } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS]));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setDomainAxis(domainAxis);
        } else {
            if (logScales[X_AXIS]) {
                LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS]));
                domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
                plot.setDomainAxis(domainAxis);
            } else {
                plot.setDomainAxis(new NumberAxis(dataTable.getColumnName(axis[X_AXIS])));
            }
        }
        Range range = getRangeForDimension(axis[X_AXIS]);
        if (range != null) {
            plot.getDomainAxis().setRange(range, true, false);
        } else {
            plot.getDomainAxis().setAutoRange(true);
        }
    }
    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

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

    // range axis
    if (axis[Y_AXIS] >= 0) {
        if (dataTable.isNominal(axis[Y_AXIS])) {
            String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(axis[Y_AXIS], i);
            }
            plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values));
        } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) {
            DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS]));
            rangeAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setRangeAxis(rangeAxis);
        } else {
            plot.setRangeAxis(new NumberAxis(dataTable.getColumnName(axis[Y_AXIS])));
        }
        Range range = getRangeForDimension(axis[Y_AXIS]);
        if (range != null) {
            plot.getRangeAxis().setRange(range, true, false);
        } else {
            plot.getRangeAxis().setAutoRange(true);
        }
    }
    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(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);
}