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

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

Introduction

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

Prototype

public void setItemFont(Font font) 

Source Link

Document

Sets the item font and sends a TitleChangeEvent to all registered listeners.

Usage

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());
    }/*  ww w. jav a2  s .  c om*/

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

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

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

    panel.add(chartPanel);

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

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

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

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

From source file:org.martus.client.swingui.actions.ActionMenuCharts.java

private LegendTitle createLegend(JFreeChart chart) {
    LegendTitle legend = new LegendTitle(chart.getPlot());
    legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.white);
    legend.setPosition(RectangleEdge.BOTTOM);
    legend.addChangeListener(chart);//from   w w w.  j a v  a2  s  . c om
    legend.setItemFont(FontHandler.getDefaultFont());
    return legend;
}

From source file:com.vgi.mafscaling.MafCompare.java

/**
 * Initialize the contents of the frame.
 *//* w  w  w . j a  va  2s .  c om*/
private void initialize() {
    try {
        ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg"));
        setTitle(Title);
        setIconImage(tableImage.getImage());
        setBounds(100, 100, 621, 372);
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setSize(Config.getCompWindowSize());
        setLocation(Config.getCompWindowLocation());
        setLocationRelativeTo(null);
        setVisible(false);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                Utils.clearTable(origMafTable);
                Utils.clearTable(newMafTable);
                Utils.clearTable(compMafTable);
                Config.setCompWindowSize(getSize());
                Config.setCompWindowLocation(getLocation());
                origMafData.clear();
                newMafData.clear();
            }
        });

        JPanel dataPanel = new JPanel();
        GridBagLayout gbl_dataPanel = new GridBagLayout();
        gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 };
        gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 };
        gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 };
        gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
        dataPanel.setLayout(gbl_dataPanel);
        getContentPane().add(dataPanel);

        JLabel origLabel = new JLabel(origMaf);
        GridBagConstraints gbc_origLabel = new GridBagConstraints();
        gbc_origLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origLabel.weightx = 0;
        gbc_origLabel.weighty = 0;
        gbc_origLabel.gridx = 0;
        gbc_origLabel.gridy = 0;
        gbc_origLabel.gridheight = 2;
        dataPanel.add(origLabel, gbc_origLabel);

        JLabel newLabel = new JLabel(newMaf);
        GridBagConstraints gbc_newLabel = new GridBagConstraints();
        gbc_newLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newLabel.weightx = 0;
        gbc_newLabel.weighty = 0;
        gbc_newLabel.gridx = 0;
        gbc_newLabel.gridy = 2;
        gbc_newLabel.gridheight = 2;
        dataPanel.add(newLabel, gbc_newLabel);

        JLabel compLabel = new JLabel("Change");
        GridBagConstraints gbc_compLabel = new GridBagConstraints();
        gbc_compLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compLabel.weightx = 0;
        gbc_compLabel.weighty = 0;
        gbc_compLabel.gridx = 0;
        gbc_compLabel.gridy = 4;
        dataPanel.add(compLabel, gbc_compLabel);

        JLabel origVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_origVoltLabel = new GridBagConstraints();
        gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origVoltLabel.weightx = 0;
        gbc_origVoltLabel.weighty = 0;
        gbc_origVoltLabel.gridx = 1;
        gbc_origVoltLabel.gridy = 0;
        dataPanel.add(origVoltLabel, gbc_origVoltLabel);

        JLabel origGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_origGsLabel = new GridBagConstraints();
        gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origGsLabel.weightx = 0;
        gbc_origGsLabel.weighty = 0;
        gbc_origGsLabel.gridx = 1;
        gbc_origGsLabel.gridy = 1;
        dataPanel.add(origGsLabel, gbc_origGsLabel);

        JLabel newVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_newVoltLabel = new GridBagConstraints();
        gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newVoltLabel.weightx = 0;
        gbc_newVoltLabel.weighty = 0;
        gbc_newVoltLabel.gridx = 1;
        gbc_newVoltLabel.gridy = 2;
        dataPanel.add(newVoltLabel, gbc_newVoltLabel);

        JLabel newGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_newGsLabel = new GridBagConstraints();
        gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newGsLabel.weightx = 0;
        gbc_newGsLabel.weighty = 0;
        gbc_newGsLabel.gridx = 1;
        gbc_newGsLabel.gridy = 3;
        dataPanel.add(newGsLabel, gbc_newGsLabel);

        JLabel compPctLabel = new JLabel(" %  ");
        GridBagConstraints gbc_compPctLabel = new GridBagConstraints();
        gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compPctLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compPctLabel.weightx = 0;
        gbc_compPctLabel.weighty = 0;
        gbc_compPctLabel.gridx = 1;
        gbc_compPctLabel.gridy = 4;
        dataPanel.add(compPctLabel, gbc_compPctLabel);

        JPanel tablesPanel = new JPanel();
        GridBagLayout gbl_tablesPanel = new GridBagLayout();
        gbl_tablesPanel.columnWidths = new int[] { 0 };
        gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 };
        gbl_tablesPanel.columnWeights = new double[] { 0.0 };
        gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 };
        tablesPanel.setLayout(gbl_tablesPanel);

        JScrollPane mafScrollPane = new JScrollPane(tablesPanel);
        mafScrollPane.setMinimumSize(new Dimension(1600, 107));
        mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20));
        mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        GridBagConstraints gbc_mafScrollPane = new GridBagConstraints();
        gbc_mafScrollPane.weightx = 1.0;
        gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START;
        gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL;
        gbc_mafScrollPane.gridx = 2;
        gbc_mafScrollPane.gridy = 0;
        gbc_mafScrollPane.gridheight = 5;
        dataPanel.add(mafScrollPane, gbc_mafScrollPane);

        origMafTable = new JTable();
        origMafTable.setColumnSelectionAllowed(true);
        origMafTable.setCellSelectionEnabled(true);
        origMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        origMafTable.setRowHeight(RowHeight);
        origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        origMafTable.setTableHeader(null);
        Utils.initializeTable(origMafTable, ColumnWidth);
        GridBagConstraints gbc_origMafTable = new GridBagConstraints();
        gbc_origMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_origMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_origMafTable.weightx = 1.0;
        gbc_origMafTable.weighty = 0;
        gbc_origMafTable.gridx = 0;
        gbc_origMafTable.gridy = 0;
        tablesPanel.add(origMafTable, gbc_origMafTable);
        excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true);

        newMafTable = new JTable();
        newMafTable.setColumnSelectionAllowed(true);
        newMafTable.setCellSelectionEnabled(true);
        newMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        newMafTable.setRowHeight(RowHeight);
        newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        newMafTable.setTableHeader(null);
        Utils.initializeTable(newMafTable, ColumnWidth);
        GridBagConstraints gbc_newMafTable = new GridBagConstraints();
        gbc_newMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_newMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_newMafTable.weightx = 1.0;
        gbc_newMafTable.weighty = 0;
        gbc_newMafTable.gridx = 0;
        gbc_newMafTable.gridy = 1;
        tablesPanel.add(newMafTable, gbc_newMafTable);
        excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true);

        compMafTable = new JTable();
        compMafTable.setColumnSelectionAllowed(true);
        compMafTable.setCellSelectionEnabled(true);
        compMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        compMafTable.setRowHeight(RowHeight);
        compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount));
        compMafTable.setTableHeader(null);
        Utils.initializeTable(compMafTable, ColumnWidth);
        NumberFormatRenderer numericRenderer = new NumberFormatRenderer();
        numericRenderer.setFormatter(new DecimalFormat("0.000"));
        compMafTable.setDefaultRenderer(Object.class, numericRenderer);
        GridBagConstraints gbc_compMafTable = new GridBagConstraints();
        gbc_compMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_compMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_compMafTable.weightx = 1.0;
        gbc_compMafTable.weighty = 0;
        gbc_compMafTable.gridx = 0;
        gbc_compMafTable.gridy = 2;
        tablesPanel.add(compMafTable, gbc_compMafTable);
        compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true);

        TableModelListener origTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = origMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, newMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    origMafData.clear();
                    String origY, origX, newY;
                    for (int i = 0; i < colCount; ++i) {
                        origY = origMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, origY)) {
                            origX = origMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origX))
                                origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false);
                            newY = newMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    origMafData.fireSeriesChanged();
                }
            }
        };

        TableModelListener newTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = newMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, origMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    newMafData.clear();
                    String newY, newX, origY;
                    for (int i = 0; i < colCount; ++i) {
                        newY = newMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, newY)) {
                            newX = newMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newX))
                                newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false);
                            origY = origMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    newMafData.fireSeriesChanged();
                }
            }
        };

        origMafTable.getModel().addTableModelListener(origTableListener);
        newMafTable.getModel().addTableModelListener(newTableListener);

        Action action = new AbstractAction() {
            private static final long serialVersionUID = 8148393537657380215L;

            public void actionPerformed(ActionEvent e) {
                TableCellListener tcl = (TableCellListener) e.getSource();
                if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) {
                    if (Pattern.matches(Utils.fpRegex,
                            origMafTable.getValueAt(1, tcl.getColumn()).toString())) {
                        double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString())
                                / 100.0 + 1.0;
                        newMafTable.setValueAt(
                                Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr,
                                1, tcl.getColumn());
                    }
                } else
                    compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn());
            }
        };

        setCompMafCellListener(new TableCellListener(compMafTable, action));

        // CHART

        JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL,
                false, true, false);
        chart.setBorderVisible(true);
        chartPanel = new ChartPanel(chart, true, true, true, true, true);
        chartPanel.setAutoscrolls(true);

        GridBagConstraints gbl_chartPanel = new GridBagConstraints();
        gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
        gbl_chartPanel.fill = GridBagConstraints.BOTH;
        gbl_chartPanel.insets = new Insets(1, 1, 1, 1);
        gbl_chartPanel.weightx = 1.0;
        gbl_chartPanel.weighty = 1.0;
        gbl_chartPanel.gridx = 0;
        gbl_chartPanel.gridy = 5;
        gbl_chartPanel.gridheight = 1;
        gbl_chartPanel.gridwidth = 3;
        dataPanel.add(chartPanel, gbl_chartPanel);

        XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
        lineRenderer.setUseFillPaint(true);
        lineRenderer.setBaseToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new DecimalFormat("0.00"), new DecimalFormat("0.00")));

        Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
        lineRenderer.setSeriesStroke(0, stroke);
        lineRenderer.setSeriesStroke(1, stroke);
        lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
        lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
        lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
        lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5));
        lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
            private static final long serialVersionUID = -4045338273187150888L;

            public String generateLabel(XYDataset dataset, int series) {
                XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
                return xys.getDescription();
            }
        });

        NumberAxis mafvDomain = new NumberAxis(XAxisName);
        mafvDomain.setAutoRangeIncludesZero(false);
        mafvDomain.setAutoRange(true);
        mafvDomain.setAutoRangeStickyZero(false);
        NumberAxis mafgsRange = new NumberAxis(YAxisName);
        mafgsRange.setAutoRangeIncludesZero(false);
        mafgsRange.setAutoRange(true);
        mafgsRange.setAutoRangeStickyZero(false);

        XYSeriesCollection lineDataset = new XYSeriesCollection();
        origMafData.setDescription(origMaf);
        newMafData.setDescription(newMaf);
        lineDataset.addSeries(origMafData);
        lineDataset.addSeries(newMafData);

        XYPlot plot = chart.getXYPlot();
        plot.setRangePannable(true);
        plot.setDomainPannable(true);
        plot.setDomainGridlinePaint(Color.DARK_GRAY);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setBackgroundPaint(new Color(224, 224, 224));

        plot.setDataset(0, lineDataset);
        plot.setRenderer(0, lineRenderer);
        plot.setDomainAxis(0, mafvDomain);
        plot.setRangeAxis(0, mafgsRange);
        plot.mapDatasetToDomainAxis(0, 0);
        plot.mapDatasetToRangeAxis(0, 0);

        LegendTitle legend = new LegendTitle(plot.getRenderer());
        legend.setItemFont(new Font("Arial", 0, 10));
        legend.setPosition(RectangleEdge.TOP);
        chart.addLegend(legend);

    } catch (Exception e) {
        logger.error(e);
    }
}

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

private void crearBarChart(Pregunta pregunta) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(Color.white);
    panelGrafica.add(panel);/*  w  ww . ja v a  2  s  .c om*/

    DefaultCategoryDataset data = new DefaultCategoryDataset();
    // Fuente de Datos

    //Calcular el nmero N de perfiles. Si N=1, no discriminar por pestanas. 
    //Si son N perfiles (N>2), hacer N+1 pestanas (la ltima representa la
    //suma de los resultados sin segregacin.
    int n = pregunta.obtenerCantidadDePerfiles();
    System.out.println(" n " + n);
    if (n > 1) {
        for (int i = 0; i < n; i++) {
            List<Opcion> opciones = pregunta.obtenerResultadoPorPerfil(i).getOpciones();
            for (Opcion opc : opciones) {
                data.setValue(opc.getCantidad(), opc.getNombre(),
                        pregunta.obtenerResultadoPorPerfil(i).getPerfil());
            }
        }
    }
    for (int i = 0; i < pregunta.obtenerCantidadDeOpciones(); i++) {
        Opcion opc = pregunta.obtenerOpcion(i);
        data.setValue(opc.getCantidad(), opc.getNombre(), "Todos");
    }

    // Creando el Grafico       
    JFreeChart chart = ChartFactory.createBarChart("\n" + pregunta.getTitulo() + "\n", "Perfil",
            "Total de votos", data, PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );

    //chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Roboto", 0, 28));

    //chart.addSubtitle(new TextTitle("Titulo jajaja"));
    //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setOutlineVisible(false);

    ChartPanel barChart = new ChartPanel(chart);
    barChart.setBounds(panel.getVisibleRect());

    //barChart.setPreferredSize(panelGrafica.getSize());
    //barChart.setBounds(panel.getVisibleRect());

    //Colores de Barras
    Paint[] 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) };

    ((org.jfree.chart.renderer.category.BarRenderer) plot.getRenderer())
            .setBarPainter(new StandardBarPainter()); // Quita Efecto luz
    BarRenderer renderer = new BarRenderer(colors);
    renderer.setColor(plot, data);

    //Numeros sobre barras
    CategoryItemRenderer renderizar;
    renderizar = plot.getRenderer();
    renderizar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderizar.setBaseItemLabelsVisible(true);
    renderizar.setItemLabelFont(new Font("Roboto", 0, 18));

    //Valores eje Y
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font("Roboto", 0, 17));
    rangeAxis.setTickLabelFont(new Font("Roboto", 0, 17));

    //Diseo categorias
    org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLabelFont(new Font("Roboto", 0, 17));
    domainAxis.setTickLabelFont(new Font("Roboto", 0, 17));
    /*domainAxis.setTickLabelPaint(new Color(160, 163, 165));
     domainAxis.setCategoryLabelPositionOffset(4);
     domainAxis.setLowerMargin(0);
     domainAxis.setUpperMargin(0);
     domainAxis.setCategoryMargin(0.2);
     */

    //Leyendas
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    Font nwfont = new Font("Roboto", 0, 18);
    legend.setItemFont(nwfont);
    legend.setBorder(0, 0, 0, 0);
    legend.setBackgroundPaint(Color.WHITE);
    legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 15));

    /*
     plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}"));
     plot.setLegendItemShape(new Rectangle(25, 25));
     */
    // Pintar
    panel.removeAll();
    panel.add(barChart);
    panel.repaint();
    panel.revalidate();
    panelGrafica.repaint();
    panelGrafica.revalidate();
}

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

public void paintParetoChart(Graphics graphics) {
    prepareData();//ww w . j a  va2  s.c  o  m

    JFreeChart chart = createChart();

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

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

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

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

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

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

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

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

        // draw outlines
        renderer.setDrawBarOutline(true);

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

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

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

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

@Override
public void updatePlotter() {

    JFreeChart chart = null;/*w ww .  j av a2s .c  om*/
    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.StackedBarChartPlotter.java

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

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
                null, // domain axis label
                null, // range axis label
                categoryDataSet, // usedCategoryDataSet, // data
                orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL
                        : PlotOrientation.HORIZONTAL, // orientation
                true, // include legend if group by column is set
                true, // tooltips
                false // URLs
        );// w w  w  .j  a  va  2 s  . c  o m

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

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLabelFont(LABEL_FONT_BOLD);
        domainAxis.setTickLabelFont(LABEL_FONT);
        String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null;
        domainAxis.setLabel(domainName);

        // rotate labels
        if (isLabelRotating()) {
            plot.getDomainAxis().setTickLabelsVisible(true);
            plot.getDomainAxis().setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
        }

        // set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setLabelFont(LABEL_FONT_BOLD);
        rangeAxis.setTickLabelFont(LABEL_FONT);
        String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null;
        rangeAxis.setLabel(rangeName);

        // bar renderer
        int length = 0;
        // if ((groupByColumn >= 0) && this.dataTable.isNominal(groupByColumn)) {
        // length = this.dataTable.getNumberOfValues(groupByColumn);
        // } else {
        // length = categoryDataSet.getColumnCount();
        // }
        if (stackGroupColumn >= 0 && this.dataTable.isNominal(stackGroupColumn)) {
            length = this.dataTable.getNumberOfValues(stackGroupColumn);
        } else {
            length = categoryDataSet.getRowCount();
        }
        final double[] colorValues = new double[length];
        for (int i = 0; i < colorValues.length; i++) {
            colorValues[i] = i;
        }
        BarRenderer renderer = new StackedBarRenderer() {

            private static final long serialVersionUID = 1912387984078591157L;

            private ColorProvider colorProvider = getColorProvider(true);

            private double minColor = Double.POSITIVE_INFINITY;
            private double maxColor = Double.NEGATIVE_INFINITY;
            {
                if (colorValues != null) {
                    for (double d : colorValues) {
                        this.minColor = MathFunctions.robustMin(this.minColor, d);
                        this.maxColor = MathFunctions.robustMax(this.maxColor, d);
                    }
                }
            }

            @Override
            public Paint getSeriesPaint(int series) {
                if (colorValues == null || minColor == maxColor || series >= colorValues.length) {
                    return ColorProvider.reduceColorBrightness(Color.RED);
                } else {
                    double normalized = (colorValues[series] - minColor) / (maxColor - minColor);
                    return colorProvider.getPointColor(normalized);
                }
            }
        };

        renderer.setBarPainter(new RapidBarPainter());
        renderer.setDrawBarOutline(true);
        renderer.setShadowVisible(false);
        plot.setRenderer(renderer);

        // 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);
    } else {
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.StackedBarChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

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

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

    prepareData();/*from   w ww . j  av a  2  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);
}

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

public void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT);
    int maxClasses = 20;
    try {/*from w w  w  .j  a va2s  .c  om*/
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Pie Chart 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.AbstractPieChartPlotter.pie_chart_plotter_parsing_error");
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = createChart(pieDataSet, createLegend);

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

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

        plot.setBackgroundPaint(Color.WHITE);
        plot.setSectionOutlinesVisible(true);
        plot.setShadowPaint(new Color(104, 104, 104, 100));

        int size = pieDataSet.getKeys().size();
        for (int i = 0; i < size; i++) {
            Comparable<?> key = pieDataSet.getKey(i);
            plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1)));

            boolean explode = false;
            for (String explosionGroup : explodingGroups) {
                if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) {
                    explode = true;
                    break;
                }
            }

            if (explode) {
                plot.setExplodePercent(key, this.explodingAmount);
            }
        }

        plot.setLabelFont(LABEL_FONT);
        plot.setNoDataMessage("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setOutlinePaint(Color.WHITE);

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

        if (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);
    } else {
        // LogService.getGlobal().logNote("Too many columns (" + categoryCount +
        // "), this chart is only able to plot up to " + MAX_CATEGORIES +
        // " different categories.");
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

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

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

    SwingUtilities.invokeLater(new Runnable() {

        @Override//from w  ww  .jav  a2 s. c om
        public void run() {
            scrollablePlotterPanel.remove(viewScrollBar);
        }
    });

    CategoryDataset usedCategoryDataSet = categoryDataSet;
    if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) {
        if (orientationIndex == ORIENTATION_TYPE_VERTICAL) {
            SwingUtilities.invokeLater(new Runnable() {

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

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

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

        usedCategoryDataSet = this.slidingCategoryDataSet;
    } else {
        this.slidingCategoryDataSet = null;
    }

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = ChartFactory.createBarChart(null, // chart title
                null, // domain axis label
                null, // range axis label
                usedCategoryDataSet, // data
                orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL
                        : PlotOrientation.HORIZONTAL, // orientation
                false, // include legend if group by column is set
                true, // tooltips
                false // URLs
        );

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

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLabelFont(LABEL_FONT_BOLD);
        domainAxis.setTickLabelFont(LABEL_FONT);
        String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null;
        domainAxis.setLabel(domainName);

        // rotate labels
        if (isLabelRotating()) {
            plot.getDomainAxis().setTickLabelsVisible(true);
            plot.getDomainAxis().setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
        }

        // set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setLabelFont(LABEL_FONT_BOLD);
        rangeAxis.setTickLabelFont(LABEL_FONT);
        String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null;
        rangeAxis.setLabel(rangeName);

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

        BarRenderer renderer = new ColorizedBarRenderer(colorValues);
        renderer.setBarPainter(new RapidBarPainter());
        renderer.setDrawBarOutline(true);
        int size = categoryDataSet.getRowCount();
        if (size > 1) {
            for (int i = 0; i < size; i++) {
                renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1)));
            }
        }
        plot.setRenderer(renderer);

        // 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 != null) {
            panel.setChart(chart);
        } else {
            panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
            scrollablePlotterPanel.add(panel, BorderLayout.CENTER);
            final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
            panel.addMouseListener(controller);
            panel.addMouseMotionListener(controller);
        }

        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        // LogService.getGlobal().logNote("Too many columns (" + categoryCount +
        // "), this chart is only able to plot up to " + MAX_CATEGORIES +
        // " different categories.");
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}