Example usage for org.jfree.ui HorizontalAlignment LEFT

List of usage examples for org.jfree.ui HorizontalAlignment LEFT

Introduction

In this page you can find the example usage for org.jfree.ui HorizontalAlignment LEFT.

Prototype

HorizontalAlignment LEFT

To view the source code for org.jfree.ui HorizontalAlignment LEFT.

Click Source Link

Document

Left alignment.

Usage

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

@Override
public void updatePlotter() {
    prepareData();//from ww  w .j  av  a 2  s  . c  o  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:org.ash.gui.StackedChart.java

/**
 * Creates the chart.// ww w  .  j  a v  a  2s.  c  om
 * 
 * @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;
}

From source file:edu.ucla.stat.SOCR.chart.SuperBoxAndWhiskerChart.java

protected JFreeChart createLegendChart(JFreeChart origchart) {

    JFreeChart legendChart = new JFreeChart("", null, new HiddenPlot(), false);

    legendChart.setBackgroundPaint(Color.white);
    CategoryPlot plot = origchart.getCategoryPlot();

    LegendTitle legendTitle = new LegendTitle(plot,
            new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0),
            new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0));
    legendChart.addLegend(legendTitle);/*from w w  w . j a va2s  .  c o m*/

    return legendChart;

}

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

public void paintBarChart(Graphics graphics) {
    int categoryCount = prepareData();
    String groupByName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null;
    String valueName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null;
    String maxClassesProperty = System.getProperty(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {// ww w .j a  v  a2  s.  c o m
        if (maxClassesProperty != null)
            maxClasses = Integer.parseInt(maxClassesProperty);
    } catch (NumberFormatException e) {
        LogService.getGlobal().log(
                "Bar Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
                LogService.WARNING);
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = createChart(categoryDataSet, groupByName, valueName, createLegend);

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

        Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
        chart.draw((Graphics2D) graphics, drawRect);
    } else {
        graphics.drawString("Too many columns (" + categoryCount + "), this chart is only able to plot up to "
                + MAX_CATEGORIES + " different categories", MARGIN, MARGIN);
    }
}

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

@Override
public void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {/*from ww w  .  j  a  v a  2s .c om*/
        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.DeviationChartPlotter.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
    SymbolAxis axis = null;
    if (this.dataTable.isSupportingColumnWeights()) {
        List<Double> weightList = new LinkedList<Double>();
        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);

    // 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 (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:fr.amap.lidar.amapvox.chart.VoxelsToChart.java

public JFreeChart createChart(String title, XYSeriesCollection dataset, String xAxisLabel, String yAxisLabel) {

    JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setDomainPannable(true);//from   w w  w . j  av a  2 s.  c  o m
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);

    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));

    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);

    LegendTitle subtitle = (LegendTitle) chart.getSubtitles().get(0);
    subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);

        Ellipse2D.Float shape = new Ellipse2D.Float(-2.5f, -2.5f, 5.0f, 5.0f);

        for (int i = 0; i < voxelFiles.length; i++) {
            renderer.setSeriesShape(i, shape);
            renderer.setSeriesPaint(i, voxelFiles[i].getSeriesParameters().getColor());
            renderer.setLegendTextPaint(i, voxelFiles[i].getSeriesParameters().getColor());
        }
    }

    return chart;
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private void setTitlePosition(Title title, PositionType position) {
    switch (position) {
    case Top://from  w  w  w .j a v a2s  .c om
        title.setPosition(RectangleEdge.TOP);
        break;
    case Bottom:
        title.setPosition(RectangleEdge.BOTTOM);
        break;
    case Left:
        title.setPosition(RectangleEdge.LEFT);
        break;
    case Right:
        title.setPosition(RectangleEdge.RIGHT);
        break;
    case TopLeft:
        title.setPosition(RectangleEdge.TOP);
        title.setHorizontalAlignment(HorizontalAlignment.LEFT);
        break;
    case TopRight:
        title.setPosition(RectangleEdge.TOP);
        title.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        break;
    case BottomLeft:
        title.setPosition(RectangleEdge.BOTTOM);
        title.setHorizontalAlignment(HorizontalAlignment.LEFT);
        break;
    case BottomRight:
        title.setPosition(RectangleEdge.BOTTOM);
        title.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        break;
    case LeftTop:
        title.setPosition(RectangleEdge.LEFT);
        title.setVerticalAlignment(VerticalAlignment.TOP);
        break;
    case LeftBottom:
        title.setPosition(RectangleEdge.LEFT);
        title.setVerticalAlignment(VerticalAlignment.BOTTOM);
        break;
    case RightTop:
        title.setPosition(RectangleEdge.RIGHT);
        title.setVerticalAlignment(VerticalAlignment.TOP);
        break;
    case RightBottom:
        title.setPosition(RectangleEdge.RIGHT);
        title.setVerticalAlignment(VerticalAlignment.BOTTOM);
        break;
    }
}

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

@Override
public void updatePlotter() {

    JFreeChart chart = null;/*from w w w  .j a v a  2s.  co  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:com.rapidminer.gui.plotter.charts.HistogramChart.java

@Override
protected void updatePlotter() {
    prepareData();/*  ww w .j a v  a2s .  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);
}

From source file:org.ash.history.detail.StackedChartDetail.java

/**
 * Creates the chart.//ww  w.j a  va2  s . c  o  m
 * 
 * @return the jfreechart
 */
private JFreeChart createChart() {

    xAxis = new DateAxis("time");
    xAxis.setLabel(null);

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

    chart.getTitle()
            .setFont(new Font(TextTitle.DEFAULT_FONT.getFontName(), TextTitle.DEFAULT_FONT.getStyle(), 14));

    plot = (XYPlot) chart.getPlot();
    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);

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

    legend.setItemFont(new Font(LegendTitle.DEFAULT_ITEM_FONT.getFontName(),
            LegendTitle.DEFAULT_ITEM_FONT.getStyle(), 10));

    chart.addSubtitle(legend);

    return chart;
}