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:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotAirTemp, boolean plotWaterTemp,
        boolean plotDewpointTemp) throws ParseException {
    Date startTime = null;//from w  w w  .  j a v  a2s  .  com
    NumberPhenomenon aTemperature = null;
    NumberPhenomenon wTemperature = null;
    NumberPhenomenon dTemperature = null;
    // default setting
    ChartPlotter plotter = new ChartPlotter();
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");

    double minValue = 100;
    double maxValue = -100;
    int plotIndex = 0;
    if (plotAirTemp) {
        aTemperature = getLocationForecastDataModel().getPhenomenen(PhenomenonName.AirTemperature.toString(),
                NumberPhenomenon.class);
        minValue = aTemperature.getMinValue() < minValue ? aTemperature.getMinValue() : minValue;
        maxValue = aTemperature.getMaxValue() > maxValue ? aTemperature.getMaxValue() : maxValue;
        startTime = aTemperature.getTime().get(0);
        plotTemperature(plotter, aTemperature, new BasicStroke(2.0f), Color.RED,
                messages.getString("label.air"), true);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(1, true);
        plotIndex++;
    }

    if (plotWaterTemp) {
        wTemperature = getOceanForecastDataModel().getPhenomenen(PhenomenonName.seaTemperature.toString(),
                NumberPhenomenon.class);
        // only plot water temperature if it is availbe for this location
        if (wTemperature != null) {
            minValue = wTemperature.getMinValue() < minValue ? wTemperature.getMinValue() : minValue;
            maxValue = wTemperature.getMaxValue() > maxValue ? wTemperature.getMaxValue() : maxValue;
            startTime = wTemperature.getTime().get(0);
            BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f);
            plotTemperature(plotter, wTemperature, dottedStroke, Color.RED, messages.getString("label.water"),
                    true);
            plotter.getPlot().getRenderer(plotIndex++).setSeriesVisibleInLegend(0, true);
        }
    }

    if (plotDewpointTemp) {
        dTemperature = getLocationForecastDataModel()
                .getPhenomenen(PhenomenonName.dewPointTemperature.toString(), NumberPhenomenon.class);
        minValue = dTemperature.getMinValue() < minValue ? dTemperature.getMinValue() : minValue;
        maxValue = dTemperature.getMaxValue() > maxValue ? dTemperature.getMaxValue() : maxValue;
        startTime = dTemperature.getTime().get(0);
        plotTemperature(plotter, dTemperature, new BasicStroke(2.0f), Color.ORANGE,
                messages.getString("label.dewpoint"), false);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true);
    }

    double tick = (maxValue - minValue) / 3.5;
    tick = Math.ceil(tick);
    double lowBound = Math.floor(minValue / (tick)) * (tick);
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 7;

    // set range axis
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(Color.RED);
    numberAxis.setTickLabelPaint(Color.RED);
    numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)");
    numberAxis.setTickUnit(new NumberTickUnit(tick));
    numberAxis.setLowerBound(lowBound);
    numberAxis.setUpperBound(upperBound);

    //Set left axis and right axis
    plotter.getPlot().setRangeAxis(0, numberAxis);
    plotter.getPlot().setRangeAxis(1, numberAxis);
    //Set the third axis and hide the third axis
    if (plotAirTemp && plotWaterTemp && plotDewpointTemp) {
        NumberAxis numberAxis2 = new NumberAxis();
        numberAxis2.setTickUnit(new NumberTickUnit(tick));
        numberAxis2.setLowerBound(lowBound);
        numberAxis2.setUpperBound(upperBound);
        plotter.getPlot().setRangeAxis(2, numberAxis2);
        plotter.getPlot().getRangeAxis(2).setVisible(false);
    }

    //Show legend at the top right position of the plot
    LegendTitle lt = new LegendTitle(plotter.getPlot());
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(255, 255, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.TOP);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.95, lt, RectangleAnchor.TOP_RIGHT);
    plotter.getPlot().addAnnotation(ta);

    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // add markers
    plotter.addDomainMarkers(getShortTermTime(startTime), timezone, locale);
    Date minDate = getShortTermTime(startTime).get(0);
    Date maxDate = getShortTermTime(startTime).get(getShortTermTime(startTime).size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    plotter.getPlot().setOutlineVisible(true);
    // invisible the domain i.e, x axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);

    return plotter.getPlot();

}

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

@Override
public void updatePlotter() {
    prepareData();/*from  w w w.  j a v a  2s. co  m*/

    JFreeChart chart = createChart(this.dataset);

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

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

    // domain axis
    SymbolAxis axis = null;
    if (this.dataTable.isSupportingColumnWeights()) {
        List<Double> weightList = new LinkedList<>();
        for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
            if ((!dataTable.isSpecial(column)) && (column != colorColumn)) {
                weightList.add(this.dataTable.getColumnWeight(column));
            }
        }
        double[] weights = new double[weightList.size()];
        int index = 0;
        for (Double d : weightList) {
            weights[index++] = d;
        }
        axis = new WeightBasedSymbolAxis(null, domainAxisMap, weights);
    } else {
        axis = new SymbolAxis(null, domainAxisMap);
    }
    axis.setTickLabelFont(LABEL_FONT);
    axis.setLabelFont(LABEL_FONT_BOLD);

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

    chart.getXYPlot().setDomainAxis(axis);

    // renderer
    final ColorizedLineAndShapeRenderer renderer = new ColorizedLineAndShapeRenderer(this.colorMap);
    plot.setRenderer(renderer);

    // legend settings
    if ((colorColumn >= 0) && (this.dataTable.isNominal(colorColumn))) {
        final LegendItemCollection legendItemCollection = new LegendItemCollection();
        for (int i = 0; i < this.dataTable.getNumberOfValues(colorColumn); i++) {
            legendItemCollection.add(new LegendItem(this.dataTable.mapIndex(colorColumn, i), null, null, null,
                    new Rectangle2D.Double(0, 0, 7, 7),
                    getColorProvider()
                            .getPointColor(i / (double) (this.dataTable.getNumberOfValues(colorColumn) - 1)),
                    new BasicStroke(0.75f), Color.GRAY));
        }
        chart.addLegend(new LegendTitle(new LegendItemSource() {

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

        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }
    } else if (colorColumn >= 0) {
        chart.addLegend(new LegendTitle(new LegendItemSource() {

            @Override
            public LegendItemCollection getLegendItems() {
                LegendItemCollection itemCollection = new LegendItemCollection();
                itemCollection.add(new LegendItem("Dummy"));
                return itemCollection;
            }
        }) {

            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, renderer.getMinColorValue(), renderer.getMaxColorValue());
                    return new BlockResult();
                } else {
                    final String minColorString = Tools.formatNumber(renderer.getMinColorValue());
                    final String maxColorString = Tools.formatNumber(renderer.getMaxColorValue());
                    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);
            }

        });
    }

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

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

From source file:grafix.graficos.eixos.Eixo.java

private void incluirLegenda(final XYPlot plot) {
    if (isLegenda()) {
        LegendTitle lt = new LegendTitle(plot);
        lt.setItemFont(new Font("Dialog", Font.PLAIN, 11));
        lt.setBackgroundPaint(new Color(255, 255, 255, 100));
        lt.setBorder(new BlockBorder(new Color(180, 180, 180)));
        lt.setPosition(RectangleEdge.TOP);
        XYTitleAnnotation ta = new XYTitleAnnotation(0.01, 0.98, lt, RectangleAnchor.TOP_LEFT);
        ta.setMaxWidth(0.48);//w  ww  .  ja  v  a 2 s  .co m
        plot.addAnnotation(ta);
    }
}

From source file:uk.ac.lkl.cram.ui.chart.AbstractChartMaker.java

/**
 * Apply some defaults to a chart, including background paint
 * and font.// w  ww .java  2s .  com
 * @param chart the chart to which defaults should be applied
 */
private void setChartDefaults(JFreeChart chart) {
    Paint backgroundPaint = UIManager.getColor("InternalFrame.background");
    //Set the background colour of the chart
    chart.setBackgroundPaint(backgroundPaint);
    //Set the background colour of the plot to be the same as the chart
    Plot plot = chart.getPlot();
    plot.setBackgroundPaint(backgroundPaint);
    //No outline around the bars
    plot.setOutlineVisible(false);
    //Get the legend
    LegendTitle legend = chart.getLegend();
    //Set the font of the legend to be the same as the platform
    legend.setItemFont(UIManager.getFont("Label.font"));
    //Set the background colour of the legend to be the same as the platform
    legend.setBackgroundPaint(backgroundPaint);
    //No frame around the legend
    legend.setFrame(BlockBorder.NONE);
    //Locate the legend to the right of the chart
    legend.setPosition(RectangleEdge.RIGHT);
}

From source file:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the binning chart.
 *
 *  @return A ChartPanel containing the binning chart.
 *//*from   w  ww. j a  v  a2  s  .c  o  m*/
private ChartPanel makeBinningChart() {
    final DefaultXYDataset binData = new DefaultXYDataset();
    final NumberFormat nf = NumberFormat.getInstance();
    final NumberAxis xAxis = new NumberAxis("Sequence identity criterion");
    nf.setMinimumFractionDigits(2);
    xAxis.setLowerBound(Binning.binLevels[0]);
    xAxis.setUpperBound(1.0D);
    xAxis.setTickUnit(new NumberTickUnit(0.05D, nf));
    LogAxis yAxis = new LogAxis("Number of bins");
    yAxis.setBase(2.0D);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance());
    yAxis.setTickUnit(new NumberTickUnit(2.0D));
    yAxis.setMinorTickMarksVisible(true);
    yAxis.setAutoRangeMinimumSize(4.0D);
    yAxis.setSmallestValue(1.0D);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    for (int i = 0; i < seriesColors.length; i++) {
        renderer.setSeriesPaint(i, seriesColors[i]);
        renderer.setSeriesStroke(i, new BasicStroke(seriesStroke[i]));
    }
    XYPlot plot = new XYPlot(binData, xAxis, yAxis, renderer);
    JFreeChart binChart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    binChart.setPadding(new RectangleInsets(0.0D, 0.0D, 0.0D, 10.0D));
    LegendTitle legend = new LegendTitle(plot);
    legend.setMargin(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.white);
    legend.setPosition(RectangleEdge.BOTTOM);
    plot.addAnnotation(new XYTitleAnnotation(0.001D, 0.999D, legend, RectangleAnchor.TOP_LEFT));
    final ChartPanel pane = new ChartPanel(binChart, false, true, true, false, false);
    // Watch for changes to the Summary object.
    summary.addObserver(new Observer() {
        public void update(Observable o, Object obj) {
            Summary s = (Summary) obj;
            ParameterEstimate estimate = s.getEstimate();
            ArrayList<BinLevel> bins = s.getBins();
            if (bins.size() > 0) {
                double[][] values = new double[2][bins.size()];
                Double low = 1.0d;
                for (int i = 0; i < bins.size(); i++) {
                    BinLevel bin = bins.get(i);
                    values[0][i] = bin.getCrit();
                    values[1][i] = bin.getLevel();
                    if (values[0][i] < low)
                        low = values[0][i];
                }
                binData.addSeries("sequences", values);
                xAxis.setLowerBound(low);
                if (low > 0.95d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.005D, nf));
                } else if (low > 0.90d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.010D, nf));
                } else if (low > 0.80d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.025D, nf));
                }
                if (estimate != null) {
                    double[][] omega = new double[2][bins.size()];
                    double[][] sigma = new double[2][bins.size()];
                    double[] omegaLine = estimate.getOmega();
                    double[] sigmaLine = estimate.getSigma();
                    for (int i = 0; i < bins.size(); i++) {
                        double crit = 1.0D - values[0][i];
                        double snp = s.getLength() * crit;
                        omega[0][i] = values[0][i];
                        sigma[0][i] = values[0][i];
                        omega[1][i] = Math.pow(2.0D, snp * omegaLine[0] + omegaLine[1]);
                        sigma[1][i] = Math.pow(2.0D, snp * sigmaLine[0] + sigmaLine[1]);
                    }
                    if (-1.0D * omegaLine[0] > MasterVariables.EPSILON) {
                        binData.addSeries("omega", omega);
                    }
                    if (-1.0D * sigmaLine[0] > MasterVariables.EPSILON) {
                        binData.addSeries("sigma", sigma);
                    }
                }
                // Repaint the summary pane.
                pane.repaint();
            }
        }
    });
    return pane;
}

From source file:chartsPK.LineChart.java

private JPanel createChartPanel(String color1, String color2) {

    XYDataset dataset = createDataset();

    boolean showLegend = false;
    boolean createURL = false;
    boolean createTooltip = false;

    JFreeChart chart = ChartFactory.createXYLineChart(getMyTitle(), getAxis().getXLabel(),
            getAxis().getYLabel(), dataset, PlotOrientation.VERTICAL, true, true, true);

    Color color;/*from   w w w .j  av  a2s . c om*/

    XYPlot plot = (XYPlot) chart.getPlot();

    try {
        Field field = Class.forName("java.awt.Color").getField(color1);
        color = (Color) field.get(null);
    } catch (Exception e) {
        color = null; // Not defined
    }
    plot.setBackgroundPaint(color);

    try {
        Field field = Class.forName("java.awt.Color").getField(color2);
        color = (Color) field.get(null);

    } catch (Exception e) {
        color = null; // Not defined
    }

    chart.setBackgroundPaint(color);

    for (int i = 0; i < dataSeries.size(); i++) {

        try {
            Field field = Class.forName("java.awt.Color").getField(dataSeries.get(i).getColor());
            color = (Color) field.get(null);
        } catch (Exception e) {
            color = null; // Not defined
        }

        plot.getRenderer().setSeriesPaint(i, color);

    }

    RectangleEdge p = RectangleEdge.BOTTOM;
    LegendTitle legend = chart.getLegend();
    switch (getLegend().getPosition().toLowerCase()) {
    case "top":
        p = RectangleEdge.TOP;
        break;
    case "bottom":
        p = RectangleEdge.BOTTOM;
        break;
    case "left":
        p = RectangleEdge.LEFT;
        break;
    case "right":
        p = RectangleEdge.RIGHT;
        break;
    }

    legend.setPosition(p);

    try {
        Field field = Class.forName("java.awt.Color").getField(getLegend().getColor());
        color = (Color) field.get(null);
    } catch (Exception e) {
        color = null; // Not defined
    }
    legend.setBackgroundPaint(color);

    return new ChartPanel(chart);
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.LinePlot.java

@Override
protected void update() {
    XYDataset dataset = null;//w  w w . jav  a 2s  . co  m

    //generate the plot data
    if (controller.getShowIndividualTraces()) {
        dataset = new DefaultTableXYDataset();

        for (ResultKey key : frame.getSelectedResults()) {
            generateIndividualSeries(key, (DefaultTableXYDataset) dataset);
        }
    } else {
        dataset = new YIntervalSeriesCollection();

        for (ResultKey key : frame.getSelectedResults()) {
            generateQuantileSeries(key, (YIntervalSeriesCollection) dataset);
        }
    }

    //create the chart
    JFreeChart chart = ChartFactory.createXYLineChart(metric, localization.getString("text.NFE"),
            localization.getString("text.value"), dataset, PlotOrientation.VERTICAL, false, true, false);
    final XYPlot plot = chart.getXYPlot();

    //setup the series renderer
    if (controller.getShowIndividualTraces()) {
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

            renderer.setSeriesStroke(i, new BasicStroke(1f, 1, 1));
            renderer.setSeriesPaint(i, paint);
        }

        plot.setRenderer(renderer);
    } else {
        DeviationRenderer renderer = new DeviationRenderer(true, false);

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

            renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
            renderer.setSeriesPaint(i, paint);
            renderer.setSeriesFillPaint(i, paint);
        }

        plot.setRenderer(renderer);
    }

    //create the legend
    final LegendItemCollection items = plot.getLegendItems();
    Iterator<?> iterator = items.iterator();
    Set<ResultKey> uniqueKeys = new HashSet<ResultKey>();

    while (iterator.hasNext()) {
        LegendItem item = (LegendItem) iterator.next();

        if (uniqueKeys.contains(item.getSeriesKey())) {
            iterator.remove();
        } else {
            uniqueKeys.add((ResultKey) item.getSeriesKey());
        }
    }

    LegendItemSource source = new LegendItemSource() {

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

    };

    LegendTitle legend = new LegendTitle(source);
    legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.WHITE);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addLegend(legend);

    //scale the axes
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRange(true);
    plot.setDomainAxis(domainAxis);

    //add overlay
    if (controller.getShowLastTrace() && !controller.getShowIndividualTraces()
            && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        DefaultTableXYDataset dataset2 = new DefaultTableXYDataset();
        XYSeries series = new XYSeries(localization.getString("text.last"), false, false);

        for (int i = 0; i < controller.getLastAccumulator().size(metric); i++) {
            series.add((Number) controller.getLastAccumulator().get("NFE", i),
                    (Number) controller.getLastAccumulator().get(metric, i));
        }

        dataset2.addSeries(series);

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
        renderer2.setSeriesStroke(0, new BasicStroke(1f, 1, 1));
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    //update the chart in the GUI
    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

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

@Override
protected void updatePlotter() {
    prepareData();/*www  . ja  va  2s  .  c  o m*/

    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Deviation 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.HistogramColorChart.parsing_property_error");
    }

    JFreeChart chart = null;
    if (nominal) {
        // ** nominal **
        int categoryCount = this.categoryDataset.getRowCount();
        boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend;

        String domainName = valueColumn >= 0 ? this.dataTable.getColumnName(valueColumn) : "Value";

        chart = ChartFactory.createBarChart(null, // title
                domainName, "Frequency", categoryDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips
                false); // urls

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setBackgroundPaint(Color.WHITE);
        plot.setForegroundAlpha(this.opaqueness);

        BarRenderer renderer = new BarRenderer();
        if (categoryDataset.getRowCount() == 1) {
            renderer.setSeriesPaint(0, Color.RED);
            renderer.setSeriesFillPaint(0, Color.RED);
        } else {
            for (int i = 0; i < categoryDataset.getRowCount(); i++) {
                Color color = getColorProvider(true)
                        .getPointColor((double) i / (double) (categoryDataset.getRowCount() - 1));
                renderer.setSeriesPaint(i, color);
                renderer.setSeriesFillPaint(i, color);
            }
        }
        renderer.setBarPainter(new RapidBarPainter());
        renderer.setDrawBarOutline(true);
        plot.setRenderer(renderer);

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

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

        // rotate labels
        if (isLabelRotating()) {
            plot.getDomainAxis().setTickLabelsVisible(true);
            plot.getDomainAxis().setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
        }
    } else {
        // ** numerical **
        int categoryCount = this.histogramDataset.getSeriesCount();
        boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend;

        String domainName = valueColumn >= 0 ? this.dataTable.getColumnName(valueColumn) : "Value";
        chart = ChartFactory.createHistogram(null, // title
                domainName, "Frequency", histogramDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips
                false); // urls

        XYPlot plot = chart.getXYPlot();
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setBackgroundPaint(Color.WHITE);
        plot.setForegroundAlpha(this.opaqueness);

        XYBarRenderer renderer = new XYBarRenderer();
        if (histogramDataset.getSeriesCount() == 1) {
            renderer.setSeriesPaint(0, Color.RED);
            renderer.setSeriesFillPaint(0, Color.RED);
        } else {
            for (int i = 0; i < histogramDataset.getSeriesCount(); i++) {
                Color color = getColorProvider(true)
                        .getPointColor((double) i / (double) (histogramDataset.getSeriesCount() - 1));
                renderer.setSeriesPaint(i, color);
                renderer.setSeriesFillPaint(i, color);
            }
        }
        renderer.setBarPainter(new RapidXYBarPainter());
        renderer.setDrawBarOutline(true);
        plot.setRenderer(renderer);

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

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

        // Correctly displays dates on x-axis
        if (datetime) {
            DateAxis dateAxis = new DateAxis();
            dateAxis.setDateFormatOverride(Tools.DATE_TIME_FORMAT.get());
            plot.setDomainAxis(dateAxis);
        }

        // range axis
        Range range = getRangeForDimension(valueColumn);
        if (range != null) {
            plot.getDomainAxis().setRange(range);
        }

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

        if (histogramDataset.getSeriesCount() == 1) {
            String key = histogramDataset.getSeriesKey(0).toString();
            int index = this.dataTable.getColumnIndex(key);
            if (index >= 0) {
                if (this.dataTable.isNominal(index)) {
                    String[] values = new String[dataTable.getNumberOfValues(index)];
                    for (int i = 0; i < values.length; i++) {
                        values[i] = dataTable.mapIndex(index, i);
                    }
                    plot.setDomainAxis(new SymbolAxis(key, values));

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

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

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

    // Disable zooming for Histogram-Charts
    panel.setRangeZoomable(false);
    panel.setDomainZoomable(false);

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

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.ja va 2s  . co  m*/
        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.HistogramChart.java

@Override
protected void updatePlotter() {
    prepareData();//from ww  w  .  j ava2s . c o  m

    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Deviation 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.HistogramChart.parsing_property_error");
    }
    int categoryCount = this.histogramDataset.getSeriesCount();
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend;

    JFreeChart chart = ChartFactory.createHistogram(null, // title
            "Value", "Frequency", histogramDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips
            false); // urls

    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setForegroundAlpha(this.opaqueness);

    XYBarRenderer renderer = new XYBarRenderer();
    if (histogramDataset.getSeriesCount() == 1) {
        renderer.setSeriesPaint(0, ColorProvider.reduceColorBrightness(Color.RED));
        renderer.setSeriesFillPaint(0, ColorProvider.reduceColorBrightness(Color.RED));
    } else {
        for (int i = 0; i < histogramDataset.getSeriesCount(); i++) {
            Color color = getColorProvider(true)
                    .getPointColor((double) i / (double) (histogramDataset.getSeriesCount() - 1));
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesFillPaint(i, color);
        }
    }
    renderer.setBarPainter(new RapidXYBarPainter());
    // renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    plot.setRenderer(renderer);

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

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

    // display correct x-Axis labels
    int count = histogramDataset.getSeriesCount();
    if (count > 0) {
        String key = histogramDataset.getSeriesKey(0).toString();
        int index = this.dataTable.getColumnIndex(key);
        if (index >= 0) {
            // Correctly displays nominal values on x-axis
            if (count == 1 && this.dataTable.isNominal(index)) {
                String[] values = new String[dataTable.getNumberOfValues(index)];
                for (int i = 0; i < values.length; i++) {
                    values[i] = dataTable.mapIndex(index, i);
                }
                plot.setDomainAxis(new SymbolAxis(key, values));
            }
            // Correctly displays dates on x-axis
            if (this.dataTable.isDateTime(index)) {
                boolean applyDateAxis = true;
                if (count > 1) {
                    for (int i = 1; i < count; i++) {
                        index = this.dataTable.getColumnIndex(histogramDataset.getSeriesKey(i).toString());
                        if (index < 0 || !this.dataTable.isDateTime(index)) {
                            applyDateAxis = false;
                            break;
                        }
                    }
                }
                if (applyDateAxis) {
                    DateAxis dateAxis = new DateAxis();
                    dateAxis.setDateFormatOverride(Tools.DATE_TIME_FORMAT.get());
                    plot.setDomainAxis(dateAxis);
                }
            }
        }

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

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

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

    // Disable zooming for Histogram-Charts
    panel.setRangeZoomable(false);
    panel.setDomainZoomable(false);

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