Example usage for org.jfree.chart.plot PiePlot setLabelGenerator

List of usage examples for org.jfree.chart.plot PiePlot setLabelGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot setLabelGenerator.

Prototype

public void setLabelGenerator(PieSectionLabelGenerator generator) 

Source Link

Document

Sets the section label generator and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java

public void setGraph() {
    if (hasGroupVariable) {
        DefaultCategoryDataset piedat = new DefaultCategoryDataset();
        chart = ChartFactory.createMultiplePieChart(chartTitle, piedat, TableOrder.BY_ROW, showLegend, true,
                false);/*from  www  .j  a  v  a 2 s  .  c o m*/

        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            TextTitle subtitle1 = new TextTitle(chartSubtitle);
            chart.addSubtitle(subtitle1);
        }

        MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
        JFreeChart subchart = plot.getPieChart();
        PiePlot p = (PiePlot) subchart.getPlot();
        p.setBackgroundPaint(Color.WHITE);
        p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        if (explode)
            p.setExplodePercent(explodeValue, explodePercent);

        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
        this.add(panel);
    } else {
        DefaultPieDataset piedat = new DefaultPieDataset();
        if (command.getSelectOneOption("view").isValueSelected("3D")) {
            chart = ChartFactory.createPieChart3D(chartTitle, piedat, showLegend, true, false);

            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setForegroundAlpha(0.5f);
            plot.setNoDataMessage("No data to display");
            if (explode)
                plot.setExplodePercent(explodeValue, explodePercent);

        } else {
            chart = ChartFactory.createPieChart(command.getFreeOption("title").getString(), piedat, showLegend,
                    true, false);
        }

        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            TextTitle subtitle = new TextTitle(chartSubtitle);
            chart.addSubtitle(subtitle);
        }

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelGap(0.02);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        plot.setBackgroundPaint(Color.WHITE);
        if (explode)
            plot.setExplodePercent(explodeValue, explodePercent);

        ChartPanel panel = new ChartPanel(chart);
        panel.getPopupMenu().addSeparator();
        this.addJpgMenuItem(this, panel.getPopupMenu());
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        this.setBackground(Color.WHITE);
        this.add(panel);
    }

}

From source file:com.dnsoft.inmobiliaria.controllers.ConsultaCCPropietariosController.java

void muestraGrafico() {

    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    //DefaultPieDataset dataDolares = new DefaultPieDataset();

    for (Propietario propietario : listPropietarios) {
        CCPropietario ccPesos = cCPropietarioDAO.findUltimoMovimiento(Moneda.PESOS, propietario);
        if (ccPesos != null) {
            dataSet.setValue(ccPesos.getSaldo(), "Pesos", propietario.toString());
        }//from  ww  w.ja  v  a2s .  c  om
        CCPropietario ccDolares = cCPropietarioDAO.findUltimoMovimiento(Moneda.DOLARES, propietario);
        if (ccDolares != null) {
            dataSet.setValue(ccDolares.getSaldo(), "Dolares", propietario.toString());
        }
    }
    // Creando el Grafico
    //JFreeChart chart = ChartFactory.createPieChart("Saldos", (PieDataset) dataSet, true, true, false);
    JFreeChart chart = ChartFactory.createMultiplePieChart("Saldos", dataSet, TableOrder.BY_ROW, false, true,
            false);
    //PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%"));
    MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    JFreeChart subchart = plot.getPieChart();
    PiePlot p = (PiePlot) subchart.getPlot();
    p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} ({2})"));
    //JFreeChart chartDolares = ChartFactory.createPieChart("Saldos en Dolares", dataDolares, true, true, false);
    // Mostrar Grafico
    ChartFrame frame = new ChartFrame("JFreeChart", chart);
    frame.pack();
    frame.setVisible(true);

}

From source file:edu.monash.merc.struts2.action.TLSumChartAction.java

@SuppressWarnings("unchecked")
public String piechart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Green", l4);
    dataset.setValue("Yellow", l3);
    dataset.setValue("Red", l2);
    dataset.setValue("Black", l1);

    chart = ChartFactory.createPieChart(dt, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setBackgroundPaint(Color.WHITE);
    //no border/*w  w w .  j  a  v a 2 s  .  c  o m*/
    plot.setOutlineStroke(null);
    //no label
    plot.setLabelGenerator(null);

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(2);
    plot.setLegendLabelGenerator(
            new StandardPieSectionLabelGenerator("{0}={2}", NumberFormat.getNumberInstance(), percentFormat));
    //set specific colors  green, yellow, red and black
    Color[] colors = { new Color(0, 140, 0), new Color(254, 172, 0), new Color(226, 0, 40),
            new Color(0, 0, 0) };
    setColor(plot, dataset, colors);

    chart.setBackgroundPaint(Color.WHITE);
    chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(11.0f));
    return SUCCESS;
}

From source file:net.footballpredictions.footballstats.swing.ResultsPieChart.java

/**
 * Updates the relative sizes of the pie chart segments.
 *//* w  w  w  . j  a va 2  s.c  om*/
public void updateGraph(int won, int drawn, int lost) {
    DefaultKeyedValues values = new DefaultKeyedValues();
    values.addValue(messageResources.getString("headToHead.won"), won);
    values.addValue(messageResources.getString("headToHead.drawn"), drawn);
    values.addValue(messageResources.getString("headToHead.lost"), lost);
    PieDataset dataSet = new DefaultPieDataset(values);

    JFreeChart chart = ChartFactory.createPieChart(title, dataSet, false, // Legend.
            true, // Tooltips.
            false); // URLs.
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setInteriorGap(0);
    plot.setSectionPaint(0, Colours.WIN);
    plot.setSectionPaint(1, Colours.DRAW);
    plot.setSectionPaint(2, Colours.DEFEAT);
    plot.setBackgroundPaint(null);
    plot.setOutlinePaint(null);
    plot.setLabelGenerator(null);
    plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} {1} ({2})"));
    setChart(chart);
}

From source file:graficos.GenerarGraficoPromociones.java

public void crear() throws ParseException {
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    ArrayList<String> reservaciones = new ArrayList();
    try {//  w  ww . j  a  v a2  s . c o m
        Dba db = new Dba(pathdb);
        db.conectar();
        String sql = "select FechaReservacion from Reservacion join Habitacion on Reservacion.IdHabitacion=Habitacion.IdHabitacion "
                + " where Habitacion.IdCategoria=" + idcategoria;
        db.prepare(sql);
        db.query.execute();
        ResultSet rs = db.query.getResultSet();

        while (rs.next()) {
            reservaciones.add(rs.getString(1));
        }
        db.desconectar();
    } catch (Exception e) {

    }
    ArrayList<String> promociones = new ArrayList();
    try {
        Dba db = new Dba(pathdb);
        db.conectar();
        String sql = "select Tipo, FechaInicio, FechaFin,Porcentaje from CategoriaDescuentoPromocion where IdCategoria="
                + idcategoria;
        db.prepare(sql);
        db.query.execute();
        ResultSet rs = db.query.getResultSet();
        while (rs.next()) {
            promociones.add(
                    rs.getString(1) + "," + rs.getString(2) + "," + rs.getString(3) + "," + rs.getString(4));
        }
        db.desconectar();
    } catch (Exception e) {

    }
    int[] count = new int[promociones.size() + 1];
    for (int i = 0; i < reservaciones.size(); i++) {
        int si = 0;
        for (int j = 0; j < promociones.size(); j++) {
            String[] partes = promociones.get(j).split(",");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date fechain = format.parse(partes[1]);
            Date fechafi = format.parse(partes[2]);
            Date fechare = format.parse(reservaciones.get(i));
            if (fechare.compareTo(fechain) >= 0 && fechare.compareTo(fechafi) <= 0) {
                si++;
                count[j]++;
            }
        }
        if (si == 0) {
            count[promociones.size()]++;
        }
    }
    for (int j = 0; j < count.length; j++) {
        if (j == promociones.size()) {
            pieDataset.setValue("Precio Normal", new Integer(count[j]));
        } else {
            String[] partes = promociones.get(j).split(",");
            pieDataset.setValue("desc: " + partes[3] + "%", new Integer(count[j]));
        }

    }
    JFreeChart chart = ChartFactory.createPieChart(
            "Porcentaje de Reservaciones Precio Normal vs Promociones y Descuentos", pieDataset, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    plot.setLabelGenerator(gen);
    try {
        ChartUtilities.saveChartAsJPEG(new File(path), chart, 500, 300);
    } catch (Exception ee) {
        System.err.println(ee.toString());
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:org.sonar.server.charts.deprecated.PieChart.java

private void configurePlot() {
    PiePlot plot = (PiePlot) jfreechart.getPlot();
    plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setDataset(dataset);//  w  w  w.  j  a va2  s.  com
    plot.setBackgroundAlpha(0.0f);
    plot.setCircular(true);
    plot.setLabelGenerator(null);
    plot.setIgnoreNullValues(true);
    plot.setIgnoreZeroValues(true);
    plot.setShadowPaint(null);
    plot.setLabelLinkMargin(0.0);
    plot.setInteriorGap(0.02);
    plot.setMaximumLabelWidth(0.10);
}

From source file:WeeklyReport.Sections.Commodities.java

private JFreeChart commodityChart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Map<Double, String> mp = new CargoTypeData().quotesByCommodityCBM();
    mp.entrySet().stream().forEach((mapEntry) -> {
        dataset.setValue(mapEntry.getValue(), mapEntry.getKey());
    });//  ww w  .  j  a v  a  2s.c  o m
    JFreeChart pieChart = ChartFactory.createPieChart3D("Commodities Quoted by Cubic Meter", dataset, true,
            true, false);

    PiePlot plot = (PiePlot) pieChart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} cbm ({2})",
            new DecimalFormat("0.000"), new DecimalFormat("0%"));
    plot.setLabelGenerator(gen);

    return pieChart;
}

From source file:com.thalesgroup.hudson.plugins.klocwork.graph.KloPieChart.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, true, false);
    chart.setBackgroundPaint(Color.white);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDataset(dataset);/*w  ww.j  a  v a  2s .c  o  m*/
    plot.setOutlinePaint(null);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No Klocwork data found.");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}"));

    // Set colours
    //plot.setOutlinePaint("New", new Color(200, 0, 0));
    int i = 0;
    if (kloConfig.getBuildGraph().isNeww() && kloReport.getNeww() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(200, 0, 0));
        i++;
    }
    if (kloConfig.getBuildGraph().isExisting() && kloReport.getExisting() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(0, 0, 200));
        i++;
    }
    if (kloConfig.getBuildGraph().isFixed() && kloReport.getFixed() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(0, 200, 0));
    }

    //plot.setOutlinePaint("Existing", new Color(0, 0, 200));
    //plot.setOutlinePaint("Fixed", new Color(0, 200, 0));

    return chart;

}

From source file:com.rapidminer.template.gui.RoleRequirementSelector.java

private JFreeChart makeChart(ExampleSet exampleSet, Attribute att) {
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    if (att.isNominal()) {
        for (String val : att.getMapping().getValues()) {
            pieDataset.setValue(val, exampleSet.getStatistics(att, Statistics.COUNT, val));
        }/* w  w w .  j  a va 2  s. c  o  m*/
    }
    JFreeChart chart = ChartFactory.createPieChart(null, pieDataset, true, false, false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.setBackgroundImageAlpha(0.0f);
    chart.setBorderVisible(false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(null);
    plot.setShadowPaint(null);
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(new Color(255, 255, 255, 0));
    plot.setBackgroundImageAlpha(0.0f);
    plot.setCircular(true);
    return chart;
}

From source file:edu.uara.wrappers.customcharts.CustomPieChart.java

/**
 * set label format/*  ww w.  j  a v a 2  s .c  o m*/
 * @param index
 */
@Override
public void setLabelFormat(int index) {
    StandardPieSectionLabelGenerator labelGenerator = null;
    switch (index) {
    case 0:
        labelGenerator = new StandardPieSectionLabelGenerator("{0}");
        break;
    case 1:
        labelGenerator = new StandardPieSectionLabelGenerator("{1}");
        break;
    case 2:
        labelGenerator = new StandardPieSectionLabelGenerator("{2}");
        break;
    case 3:
        labelGenerator = new StandardPieSectionLabelGenerator("{0}\n\r{1}");
        break;
    case 4:
        labelGenerator = new StandardPieSectionLabelGenerator("{0}\n\r{2}");
        break;
    }
    Plot plot = chart.getPlot();
    if (plot instanceof MultiplePiePlot) {

        MultiplePiePlot p = (MultiplePiePlot) plot;
        JFreeChart pieCh = p.getPieChart();
        PiePlot piePlot = (PiePlot) pieCh.getPlot();
        piePlot.setLabelGenerator(labelGenerator);
    } else {
        PiePlot p = (PiePlot) plot;
        p.setLabelGenerator(labelGenerator);
    }
}