Search in sources :

Example 11 with PiePlot

use of org.jfree.chart.plot.PiePlot in project MtgDesktopCompanion by nicho92.

the class ManaRepartitionPanel method refresh.

private void refresh() {
    this.removeAll();
    JFreeChart chart = ChartFactory.createPieChart3D(// chart title
    "Color repartition", // data
    getManaRepartitionDataSet(), // include legend
    false, true, true);
    pane = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("Black", Color.BLACK);
    plot.setSectionPaint("White", Color.WHITE);
    plot.setSectionPaint("Blue", Color.BLUE);
    plot.setSectionPaint("Green", Color.GREEN);
    plot.setSectionPaint("Red", Color.RED);
    plot.setSectionPaint("Multi", Color.YELLOW);
    plot.setSectionPaint("Uncolor", Color.GRAY);
    plot.setSectionPaint("black", Color.BLACK);
    plot.setSectionPaint("white", Color.WHITE);
    plot.setSectionPaint("blue", Color.BLUE);
    plot.setSectionPaint("green", Color.GREEN);
    plot.setSectionPaint("red", Color.RED);
    plot.setSectionPaint("multi", Color.YELLOW);
    plot.setSectionPaint("uncolor", Color.GRAY);
    plot.setSimpleLabels(true);
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);
    this.add(pane, BorderLayout.CENTER);
    this.revalidate();
    this.repaint();
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 12 with PiePlot

use of org.jfree.chart.plot.PiePlot in project tdq-studio-se by Talend.

the class ChartDecorator method decorate.

/**
 * DOC bZhou Comment method "decorate".
 *
 * @param chart
 */
public static void decorate(JFreeChart chart, PlotOrientation orientation) {
    if (chart != null) {
        // TDQ-11522: Set white background on charts in the editors
        chart.setBackgroundPaint(Color.white);
        // TDQ-11522~
        Plot plot = chart.getPlot();
        if (plot instanceof CategoryPlot) {
            decorateCategoryPlot(chart, orientation);
            CategoryDataset dataset = chart.getCategoryPlot().getDataset();
            int rowCount = dataset != null ? dataset.getRowCount() : 20;
            for (int i = 0; i < rowCount; i++) {
                // by zshen bug 14173 add the color in the colorList when chart need more the color than 8.
                if (i >= COLOR_LIST.size()) {
                    COLOR_LIST.add(generateRandomColor(COLOR_LIST));
                }
                // ~14173
                ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, COLOR_LIST.get(i));
            }
        } else if (plot instanceof XYPlot) {
            decorateXYPlot(chart);
            int count = chart.getXYPlot().getDataset().getSeriesCount();
            for (int i = 0; i < count; i++) {
                // by zshen bug 14173 add the color in the colorList when chart need the colors more than 8.
                if (i >= COLOR_LIST.size()) {
                    COLOR_LIST.add(generateRandomColor(COLOR_LIST));
                }
                // ~14173
                ((XYPlot) plot).getRenderer().setSeriesPaint(i, COLOR_LIST.get(i));
            }
        } else if (plot instanceof PiePlot) {
            decoratePiePlot(chart);
            // ADD msjian TDQ-8046 2013-10-17: add the color's control for pie chart
            PieDataset piedataset = ((PiePlot) plot).getDataset();
            for (int i = 0; i < piedataset.getItemCount(); i++) {
                if (i >= PIE_COLOR_LIST.size()) {
                    PIE_COLOR_LIST.add(generateRandomColor(PIE_COLOR_LIST));
                }
                Comparable<?> key = piedataset.getKey(i);
                ((PiePlot) plot).setSectionPaint(key, PIE_COLOR_LIST.get(i));
            }
        // TDQ-8046~
        }
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) PieDataset(org.jfree.data.general.PieDataset) XYPlot(org.jfree.chart.plot.XYPlot) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Plot(org.jfree.chart.plot.Plot) PiePlot(org.jfree.chart.plot.PiePlot) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) PiePlot(org.jfree.chart.plot.PiePlot) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint)

Example 13 with PiePlot

use of org.jfree.chart.plot.PiePlot in project tdq-studio-se by Talend.

the class ChartDecorator method decorateDuplicatePieChart.

public static void decorateDuplicatePieChart(JFreeChart chart) {
    if (chart != null) {
        Plot plot = chart.getPlot();
        if (plot instanceof PiePlot) {
            decoratePiePlot(chart);
            // ADD msjian TDQ-8046 2013-10-17: add the color's control for pie chart
            PieDataset piedataset = ((PiePlot) plot).getDataset();
            for (int i = 0; i < piedataset.getItemCount(); i++) {
                if (i >= DUPLICATE_PIE_COLOR_LIST.size()) {
                    DUPLICATE_PIE_COLOR_LIST.add(generateRandomColor(DUPLICATE_PIE_COLOR_LIST));
                }
                Comparable<?> key = piedataset.getKey(i);
                ((PiePlot) plot).setSectionPaint(key, DUPLICATE_PIE_COLOR_LIST.get(i));
            }
        // TDQ-8046~
        }
    }
}
Also used : PieDataset(org.jfree.data.general.PieDataset) XYPlot(org.jfree.chart.plot.XYPlot) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Plot(org.jfree.chart.plot.Plot) PiePlot(org.jfree.chart.plot.PiePlot) PiePlot(org.jfree.chart.plot.PiePlot) Paint(java.awt.Paint)

Example 14 with PiePlot

use of org.jfree.chart.plot.PiePlot in project pdfbox-graphics2d by rototor.

the class MultiPageTest method createChartCategory.

/**
 * Creates a sample chart for the given dataset.
 *
 * @param dataset
 *            the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChartCategory(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 4", dataset, TableOrder.BY_COLUMN, false, true, false);
    chart.setBackgroundPaint(new Color(216, 255, 216));
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final JFreeChart subchart = plot.getPieChart();
    // final StandardLegend legend = new StandardLegend();
    // legend.setItemFont(new Font("SansSerif", Font.PLAIN, 8));
    // legend.setAnchor(Legend.SOUTH);
    // subchart.setLegend(legend);
    plot.setLimit(0.10);
    final PiePlot p = (PiePlot) subchart.getPlot();
    // p.setLabelGenerator(new StandardPieItemLabelGenerator("{0}"));
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    p.setInteriorGap(0.30);
    return chart;
}
Also used : MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 15 with PiePlot

use of org.jfree.chart.plot.PiePlot in project dhis2-core by dhis2.

the class DefaultChartService method getMultiplePieChart.

private JFreeChart getMultiplePieChart(PlotData plotData, CategoryDataset[] dataSets) {
    JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart(plotData.getName(), dataSets[0], TableOrder.BY_ROW, !plotData.isHideLegend(), false, false);
    setBasicConfig(multiplePieChart, plotData);
    if (multiplePieChart.getLegend() != null) {
        multiplePieChart.getLegend().setItemFont(SUB_TITLE_FONT);
    }
    MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
    JFreeChart pieChart = multiplePiePlot.getPieChart();
    pieChart.setBackgroundPaint(DEFAULT_BACKGROUND_COLOR);
    pieChart.getTitle().setFont(SUB_TITLE_FONT);
    PiePlot piePlot = (PiePlot) pieChart.getPlot();
    piePlot.setBackgroundPaint(DEFAULT_BACKGROUND_COLOR);
    piePlot.setOutlinePaint(DEFAULT_BACKGROUND_COLOR);
    piePlot.setLabelFont(LABEL_FONT);
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
    piePlot.setSimpleLabels(true);
    piePlot.setIgnoreZeroValues(true);
    piePlot.setIgnoreNullValues(true);
    piePlot.setShadowXOffset(0d);
    piePlot.setShadowYOffset(0d);
    for (int i = 0; i < dataSets[0].getColumnCount(); i++) {
        piePlot.setSectionPaint(dataSets[0].getColumnKey(i), COLORS[(i % COLORS.length)]);
    }
    return multiplePieChart;
}
Also used : MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

PiePlot (org.jfree.chart.plot.PiePlot)40 JFreeChart (org.jfree.chart.JFreeChart)22 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)16 Font (java.awt.Font)14 TextTitle (org.jfree.chart.title.TextTitle)11 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)10 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)9 RectangleInsets (org.jfree.ui.RectangleInsets)9 Color (java.awt.Color)8 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)8 DecimalFormat (java.text.DecimalFormat)6 PieDataset (org.jfree.data.general.PieDataset)6 BasicStroke (java.awt.BasicStroke)5 Plot (org.jfree.chart.plot.Plot)5 StandardPieURLGenerator (org.jfree.chart.urls.StandardPieURLGenerator)5 ChartPanel (org.jfree.chart.ChartPanel)4 Test (org.junit.Test)4 GradientPaint (java.awt.GradientPaint)3 Paint (java.awt.Paint)3 Iterator (java.util.Iterator)3