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:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample pie chart.
 *
 * @return a sample pie chart.//from  ww w .j a v a2 s  .  co  m
 */
public JFreeChart createPieChartTwo() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("pie.pie2.title");
    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final Comparable category = (Comparable) data.getColumnKeys().get(1);
    final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category);
    final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(Color.lightGray);
    final PiePlot pie = (PiePlot) chart.getPlot();
    pie.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    pie.setBackgroundImage(JFreeChart.INFO.getLogo());
    pie.setBackgroundPaint(Color.white);
    pie.setBackgroundAlpha(0.6f);
    pie.setForegroundAlpha(0.75f);
    return chart;

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final Plot plot = chart.getPlot();
    final MultiplePiePlot mpp = (MultiplePiePlot) plot;
    final JFreeChart pc = mpp.getPieChart();
    configureSubChart(pc);/*  www . j  a  v a  2s.  c o  m*/

    final PiePlot pp = (PiePlot) pc.getPlot();
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula()));
    }
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula()));
    }

    if (shadowPaint != null) {
        pp.setShadowPaint(shadowPaint);
    }
    if (shadowXOffset != null) {
        pp.setShadowXOffset(shadowXOffset.doubleValue());
    }
    if (shadowYOffset != null) {
        pp.setShadowYOffset(shadowYOffset.doubleValue());
    }

    final CategoryDataset c = mpp.getDataset();
    if (c != null) {
        final String[] colors = getSeriesColor();
        final int keysSize = c.getColumnKeys().size();
        for (int i = 0; i < colors.length; i++) {
            if (keysSize > i) {
                pp.setSectionPaint(c.getColumnKey(i), parseColorFromString(colors[i]));
            }
        }
    }

    if (StringUtils.isEmpty(getLabelFont()) == false) {
        pp.setLabelFont(Font.decode(getLabelFont()));
    }

    if (Boolean.FALSE.equals(getItemsLabelVisible())) {
        pp.setLabelGenerator(null);
    } else {
        final ExpressionRuntime runtime = getRuntime();
        final Locale locale = runtime.getResourceBundleFactory().getLocale();

        final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale);
        final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale);

        final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(),
                new DecimalFormatSymbols(locale));
        numFormat.setRoundingMode(RoundingMode.HALF_UP);

        final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(),
                new DecimalFormatSymbols(locale));
        percentFormat.setRoundingMode(RoundingMode.HALF_UP);

        final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                multipieLabelFormat, numFormat, percentFormat);
        pp.setLabelGenerator(labelGen);
    }
}

From source file:cnu.eslab.fileTest.NewJFrame.java

public void PieGraphGenerate(String[] arGrop, double[] arValue, String arTitle, String arSubTitle) {
    // ??   ?./*from   www.j a  v  a  2 s.  com*/
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue(arGrop[0], arValue[0]); //CPU
    data.setValue(arGrop[1], arValue[1]); //WIFI
    data.setValue(arGrop[5], arValue[5]); //3G
    data.setValue(arGrop[2], arValue[2]); //LED
    data.setValue(arGrop[3], arValue[3]); //GPS
    data.setValue(arGrop[4], arValue[4]); //AUDIO

    //offset data .
    RectangleInsets pieOffset = new RectangleInsets(50.0, 50.0, 50.0, 50.0);

    //  ?  ?.
    JFreeChart chart = ChartFactory.createPieChart(arTitle, data, true, true, false);
    TextTitle subTitle = new TextTitle(arSubTitle);
    chart.setBackgroundPaint(Color.WHITE);
    chart.addSubtitle(subTitle);
    PiePlot pieplot = (PiePlot) chart.getPlot();
    pieplot.setNoDataMessage("No data available");
    pieplot.setExplodePercent("LED", 0.20000000000000001D);
    pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} mW) ({2} percent)"));
    pieplot.setLabelBackgroundPaint(new Color(220, 220, 220));
    pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
    //? 
    /*pieplot.setSectionPaint(arGrop[0], new Color(0,0,0));
    pieplot.setSectionPaint(arGrop[1], new Color(60,60,60));
    pieplot.setSectionPaint(arGrop[2], new Color(120,120,120));
    pieplot.setSectionPaint(arGrop[4], new Color(180,180,180));*/

    //pieplot.setSimpleLabels(true);
    //pieplot.setSimpleLabelOffset(pieOffset);   //?? offset? .

    pieplot.setInteriorGap(0.0D);

    // ??   ?.
    ChartPanel chartPanel = new ChartPanel(chart);
    JFrame f = new JFrame("");
    f.setSize(600, 600);
    f.getContentPane().add(chartPanel);

    // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:com.polivoto.vistas.acciones.Datos.java

private JFreeChart crearChartPie(PieDataset dataset, String titulo) {
    JFreeChart chart = ChartFactory.createPieChart(titulo, dataset, false, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(290);//w w w  .  j a  va2 s .c o m
    plot.setDirection(Rotation.ANTICLOCKWISE);

    plot.setNoDataMessage("No hay votos");
    try {
        if (ac.getConteoOpcionesPregunta().getJSONObject(pox).getInt("participantes") != 0) {
            int j = 0;
            for (int i = 0; i < ac.getConteoOpcionesPregunta().getJSONObject(pox).getJSONArray("conteo")
                    .length(); i++) {
                try {
                    if (ac.getConteoOpcionesPregunta().getJSONObject(pox).getJSONArray("conteo")
                            .getJSONObject(i).getString("reactivo").equals("Anular mi voto")) {
                        plot.setSectionPaint("Nulo", Color.lightGray);
                    } else {
                        plot.setSectionPaint(ac.getConteoOpcionesPregunta().getJSONObject(pox)
                                .getJSONArray("conteo").getJSONObject(i).getString("reactivo"), colores.get(j));
                        j++;
                    }
                } catch (JSONException ex) {
                    ex.printStackTrace();
                }
            }
        }
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    plot.setSimpleLabels(true);
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {2} de votos",
            new DecimalFormat("0"), new DecimalFormat("0.000%"));
    plot.setLabelGenerator(gen);
    if (rotating) {
        final Rotator rotate = new Rotator(plot);
        rotate.start();
    }
    return chart;
}

From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

/**
 * Creates the chart./* w ww .j  a  v a2s  . c om*/
 * 
 * @param dataset
 *            the dataset.
 * @param loader
 *            the pie chart loader
 * @param dataRequested
 *            flag indicating if the data have been requested for the current loader and the
 *            current interval
 * @return the pie chart
 */
private JFreeChart createChart(PieDataset dataset, String title, IPieChartLoader loader,
        boolean dataRequested) {

    JFreeChart chart = ChartFactory.createPieChart(title, dataset, HAS_LEGEND, HAS_TOOLTIPS, HAS_URLS);

    // legend
    if (HAS_LEGEND) {
        LegendTitle legend = chart.getLegend();
        legend.setPosition(RectangleEdge.LEFT);
    }

    // plot
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage(
            "No data available " + (dataRequested ? "in this time interval" : "yet. Press the Load button."));
    plot.setCircular(true);
    plot.setLabelGenerator(null); // hide labels
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setShadowPaint(Color.WHITE);
    plot.setBaseSectionPaint(Color.WHITE);
    StandardPieToolTipGenerator g = (StandardPieToolTipGenerator) plot.getToolTipGenerator();
    NumberFormat format = ValueLabelProvider.getActualFormat(loader.getFormat(), getTimeUnit());
    StandardPieToolTipGenerator sg = new StandardPieToolTipGenerator(g.getLabelFormat(), format,
            g.getPercentFormat());
    plot.setToolTipGenerator(sg);

    for (Object o : dataset.getKeys()) {
        String key = (String) o;
        plot.setSectionPaint(key, loader.getColor(key).getAwtColor());
    }
    return chart;
}

From source file:beproject.MainGUI.java

void createCountryPieChart() throws SQLException {
    DefaultPieDataset dataset = new DefaultPieDataset();
    String tmp = "select country, count(country) from tweets where moviename='" + movieName
            + "' group by country";
    ResultSet rs = stmt.executeQuery(tmp);
    while (rs.next()) {
        String tmp1 = rs.getString(1);
        if (tmp1.equals(""))
            tmp1 = "Others";
        dataset.setValue(tmp1, rs.getInt(2));
    }// w ww.  java2 s .c om

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));

    JFreeChart chart = ChartFactory.createPieChart("Tweets by Country", dataset, true, true, false);
    PiePlot p = (PiePlot) chart.getPlot();
    p.setSectionPaint("Others", Color.gray);
    //p.setSectionPaint(KEY2, Color.red);
    //p.setExplodePercent(KEY1, 0.10);
    p.setSimpleLabels(true);
    p.setLabelGenerator(gen);
    if (countryPieChart == null) {
        countryPieChart = new ChartPanel(chart);
        countryPanel.add(countryPieChart);
    } else {
        countryPanel.remove(countryPieChart);
        countryPieChart = new ChartPanel(chart);
        countryPanel.add(countryPieChart);
    }

    countryPanel.validate();
}

From source file:lucee.runtime.tag.Chart.java

private void chartPie() throws PageException, IOException {
    // do dataset
    DefaultPieDataset dataset = new DefaultPieDataset();
    ChartSeriesBean csb = _series.get(0);

    ChartDataBean cdb;// ww w .j  a  v  a  2 s. c o  m

    List datas = csb.getDatas();
    if (sortxaxis)
        Collections.sort(datas);
    Iterator itt = datas.iterator();
    while (itt.hasNext()) {
        cdb = (ChartDataBean) itt.next();
        dataset.setValue(cdb.getItemAsString(), cdb.getValue());
    }

    JFreeChart chart = show3d ? ChartFactory.createPieChart3D(title, dataset, false, true, true)
            : ChartFactory.createPieChart(title, dataset, false, true, true);

    Plot p = chart.getPlot();
    PiePlot pp = (PiePlot) p;

    Font _font = getFont();
    pp.setLegendLabelGenerator(new PieSectionLegendLabelGeneratorImpl(_font, chartwidth));
    pp.setBaseSectionOutlinePaint(Color.GRAY); // border
    pp.setLegendItemShape(new Rectangle(7, 7));
    pp.setLabelFont(new Font(font, 0, 11));
    pp.setLabelLinkPaint(COLOR_333333);
    pp.setLabelLinkMargin(-0.05);
    pp.setInteriorGap(0.123);
    pp.setLabelGenerator(new PieSectionLabelGeneratorImpl(labelFormat));

    databackgroundcolor = backgroundcolor;

    setBackground(chart, p);
    setBorder(chart, p);
    setLegend(chart, p, _font);
    set3d(p);
    setFont(chart, _font);
    setTooltip(chart);
    setScale(chart);

    // Slice Type and colors
    boolean doSclice = pieslicestyle == PIE_SLICE_STYLE_SLICED;
    Color[] colors = csb.getColorlist();
    Iterator it = csb.getDatas().iterator();
    int count = 0;
    while (it.hasNext()) {
        cdb = (ChartDataBean) it.next();
        if (doSclice)
            pp.setExplodePercent(cdb.getItemAsString(), 0.13);

        if (count < colors.length) {
            pp.setSectionPaint(cdb.getItemAsString(), colors[count]);
        }
        count++;
    }

    writeOut(chart);
}

From source file:msi.gama.outputs.layers.ChartLayerStatement.java

private void createSlices(final IScope scope) throws GamaRuntimeException {
    int i = 0;/* ww  w  .  j  av  a  2  s.co m*/
    dataset = new DefaultPieDataset();
    final PiePlot plot = (PiePlot) chart.getPlot();
    for (final ChartData e : datas) {
        final String legend = e.getName();
        ((DefaultPieDataset) dataset).insertValue(i++, legend, null);
        history.append(legend);
        history.append(',');
    }
    if (history.length() > 0) {
        history.deleteCharAt(history.length() - 1);
    }
    history.append(Strings.LN);
    plot.setDataset((DefaultPieDataset) dataset);
    i = 0;
    for (final ChartData e : datas) {
        plot.setSectionPaint(i++, e.getColor());
    }
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})"));
    if (exploded) {
        for (final Object c : ((DefaultPieDataset) dataset).getKeys()) {
            plot.setExplodePercent((Comparable) c, 0.20);
        }
    }
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(getLabelFont());
    plot.setNoDataMessage("No data available yet");
    plot.setCircular(true);
    plot.setLabelGap(0.02);
    plot.setInteriorGap(0);
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());

    plot.setNoDataMessage(chartDefinition.getNoDataMessage());

    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(),
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }/* w  ww.j av  a  2  s  .  c om*/
    plot.setOutlineStroke(null); // TODO define outline stroke

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }

            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }

    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            } else {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                        "{0} = {1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }

        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));

    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        }
    }
}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

private void renderChartInfo() {
    HashMap<Object, Marker> marks = new HashMap<>();
    DefaultPieDataset dataset = buildDataset(marks);

    JFreeChart chart = ChartFactory.createPieChart(null, // chart title
            dataset, // data
            true, // include legend
            true, false);/*from   w w  w  .  j av a 2  s . c  om*/
    chart.setBackgroundPaint(null);
    //chart.setBorderStroke(null);
    chart.setBorderVisible(false);
    final PiePlot plot = (PiePlot) chart.getPlot();
    // plot.setBackgroundPaint(null);
    //  plot.setShadowPaint(null);

    for (Object o : marks.keySet()) {
        if (iCurrentView == ID_ALLY_CHART) {
            Ally a = (Ally) o;
            plot.setSectionPaint(a.getTag(), marks.get(a).getMarkerColor());
        } else {
            Tribe t = (Tribe) o;
            plot.setSectionPaint(t.getName(), marks.get(t).getMarkerColor());
        }
    }
    //plot.setCircular(true);
    //  plot.setMaximumLabelWidth(30.0);
    /*
        * plot.setLabelGenerator(new StandardPieSectionLabelGenerator( "{0} = {2}", NumberFormat.getNumberInstance(),
        * NumberFormat.getPercentInstance()));
        */
    //   chart.getLegend().setVerticalAlignment(VerticalAlignment.CENTER);
    //  chart.getLegend().setPosition(RectangleEdge.RIGHT);
    // plot.setMaximumLabelWidth(20.0);
    plot.setLabelGenerator(null);
    plot.setBackgroundPaint(Constants.DS_BACK);
    /*
     * plot.setInteriorGap(0.0); plot.setLabelGap(0.0);
     */
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}",
            NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));

    /*
     * plot.getL plot.setLabelFont(g2d.getFont().deriveFont(10.0f));
     */

    //plot.setLabelGenerator(null);

    //plot.setMaximumLabelWidth(30.0);
    //plot.getLabelDistributor().distributeLabels(10.0, 20.0);
    //chart.draw(g2d, new Rectangle2D.Float(20, 20, 100, 100));

    //  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    plot.setOutlineVisible(false);
    mChartImage = chart.createBufferedImage(getWidth(), getHeight());
    //chart.draw(g2d, new Rectangle2D.Float(50, 50, 400, 400));
    //g2d.drawImage(bi, 30, 30, null);

    //  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));

    //bi = chart.createBufferedImage(240, 240);
    // g2d.drawImage(bi, 30, 30, null);
}