Example usage for org.jfree.chart.labels PieSectionLabelGenerator PieSectionLabelGenerator

List of usage examples for org.jfree.chart.labels PieSectionLabelGenerator PieSectionLabelGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.labels PieSectionLabelGenerator PieSectionLabelGenerator.

Prototype

PieSectionLabelGenerator

Source Link

Usage

From source file:org.openfaces.component.chart.impl.plots.PiePlot3DAdapter.java

private void setupLegendLabels(PiePlot plot, Chart chart, PieChartView chartView) {
    if (!chart.isLegendVisible())
        return;//from w  w w .  ja v a  2 s  .c  om

    ChartLegend legend = chart.getLegend();
    if (legend == null || legend.getLabels() == null)
        return;

    final ChartLabels labels = legend.getLabels();
    if (labels.getText() != null) {
        // simple text = the same string for every item
        plot.setLegendLabelGenerator(new PieSectionLabelGenerator() {
            public String generateSectionLabel(PieDataset pieDataset, Comparable comparable) {
                return labels.getText();
            }

            public AttributedString generateAttributedSectionLabel(PieDataset dataset, Comparable key) {
                return null;
            }
        });
    } else if (labels.getDynamicText() != null) {
        plot.setLegendLabelGenerator(new DynamicPieGenerator(chartView, labels.getDynamicText()));
    } else {
        plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator());
    }

}

From source file:probe.com.view.body.quantcompare.PieChart.java

private String initPieChart(int width, int height, String title) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], values[x]);

    }//from   w  ww  .  jav  a 2 s .c  o  m
    PiePlot plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 10));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    JFreeChart chart = new JFreeChart(plot);
    //        chart.setTitle(new TextTitle(title, new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 10));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:jmemorize.gui.swing.panels.CardCounterPanel.java

private void setupPiePlot(PiePlot plot) {
    plot.setMaximumLabelWidth(0.0);//from  ww w .  j av  a2  s  .c  o m
    plot.setLabelGap(0.0);
    plot.setInteriorGap(0.0);
    //piePlot.setLabelLinkMargin(0.0);
    plot.setCircular(true);
    plot.setLabelGenerator(new PieSectionLabelGenerator() {
        public String generateSectionLabel(PieDataset arg0, Comparable arg1) {
            return null;
        }

        public AttributedString generateAttributedSectionLabel(PieDataset arg0, Comparable arg1) {
            return null;
        }
    });
    //piePlot.setForegroundAlpha(0.5f);

    plot.setSectionPaint(Localization.get(LC.STATUS_LEARNED), ColorConstants.LEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.STATUS_PARTIAL), ColorConstants.PARTIAL_LEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.STATUS_UNLEARNED), ColorConstants.UNLEARNED_CARDS);
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.interactivepiechartfilters.JfreeDivaPieChartFilter.java

private String initPieChart(int width, int height) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], new Double(values[x]));

    }/*w  w  w .  jav  a 2s .co m*/
    plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 15));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    chart = new JFreeChart(plot);
    chart.setTitle(
            new TextTitle(Local_Filter_Manager.getFilterTitle(filter_Id), new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 12));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JFreeChart createPieChart(String chartName, DBSeerDataSet dataset) throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";");

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");
    timestamp = runner.getVariableDouble("timestamp");

    DefaultPieDataset pieDataSet = new DefaultPieDataset();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    if (numXCellArray != numYCellArray) {
        JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.",
                "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE);
        return null;
    }/*from   w  w w  .j a  va 2 s.  c o m*/

    final java.util.List<String> transactionTypeNames = dataset.getTransactionTypeNames();

    for (int i = 0; i < numYCellArray; ++i) {
        double[] xArray = (double[]) xCellArray[i];
        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        int xLength = xArray.length;
        int row = (int) yArraySize[0];
        int col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            if (c < transactionTypeNames.size()) {
                String name = transactionTypeNames.get(c);
                if (!name.isEmpty()) {
                    //                     pieDataSet.setValue(name, new Double(yArray.getRealValue(0, c)));
                    pieDataSet.setValue(name, yArray[c]);
                } else {
                    //                     pieDataSet.setValue("Transaction Type " + (c+1), yArray.getRealValue(0, c));
                    pieDataSet.setValue("Transaction Type " + (c + 1), yArray[c]);
                }
            }
        }
    }

    JFreeChart chart = ChartFactory.createPieChart(title, pieDataSet, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"),
            new DecimalFormat("0%")));
    plot.setLegendLabelGenerator(new PieSectionLabelGenerator() {
        @Override
        public String generateSectionLabel(PieDataset pieDataset, Comparable comparable) {
            return (String) comparable;
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pieDataset, Comparable comparable) {
            return null;
        }
    });
    return chart;
}