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

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

Introduction

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

Prototype

public void setSectionPaint(int section, Paint paint) 

Source Link

Document

Sets the paint used to fill a section of the pie and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:draw.charts.PieRenderer.java

/**
 * Iterates through the Pie dataset keys and assigns proper colors to their
 * segments./*from  w  w  w .ja va  2s. co  m*/
 *
 * @param plot PiePlot object.
 * @param dataset DefaultPieDataset that the charts is drawn from.
 */
public void setColor(PiePlot plot, DefaultPieDataset dataset) {
    List<Comparable> keys = dataset.getKeys();
    int colorIndex;
    for (int i = 0; i < keys.size(); i++) {
        colorIndex = i % this.colors.length;
        plot.setSectionPaint(keys.get(i), this.colors[colorIndex]);
    }
}

From source file:com.ouc.cpss.view.SupTradeChartBuilder.java

private static JFreeChart createJFreeChart(PieDataset dataset) {
    /**/*from w w w.  ja v  a 2s .c  o m*/
     * JFreeChart
     */
    //?     
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //     
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //    
    standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
    //?     
    standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
    //?   
    ChartFactory.setChartTheme(standardChartTheme);
    //??  
    //createPieChart 2D; createPieChart3D  3D
    JFreeChart chart = ChartFactory.createPieChart("", dataset, true, true, false);

    //,?
    chart.setTitle(new TextTitle("", new Font("", Font.ITALIC, 22)));

    //?
    LegendTitle legend = chart.getLegend(0);
    //,ture,?
    legend.setItemFont(new Font("", Font.BOLD, 20));

    //?(??)
    PiePlot plot = (PiePlot) chart.getPlot();
    //?==?
    plot.setLabelFont(new Font("", Font.BOLD, 22));
    //
    plot.setBaseSectionOutlinePaint(Color.BLUE);
    //
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.5f));
    //?,??,??
    plot.setDirection(Rotation.CLOCKWISE);//,Rotation.CLOCKWISE
    //()
    plot.setStartAngle(70);
    //???
    //plot.setExplodePercent(1, 0.5D);
    //plot.setExplodePercent("One", 0.5D);
    //,3D?
    plot.setExplodePercent(dataset.getKey(0), 0.1d);
    //
    plot.setLabelLinkPaint(Color.BLUE);
    //
    plot.setLabelOutlinePaint(Color.black);
    //
    plot.setLabelShadowPaint(Color.RED);
    //
    plot.setSectionPaint(1, Color.BLACK);
    // :,{0},{1},{2}?,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}\r\n{2}",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));

    //
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={2}"));
    //:(true),(false)
    plot.setCircular(true);
    //?
    plot.setNoDataMessage("??...");

    //???
    plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    //
    //plot.setURLGenerator(new StandardPieURLGenerator("detail.jsp"));

    return chart;
}

From source file:Visuals.PieChart.java

public ChartPanel drawPieChart() {
    DefaultPieDataset piedataset = new DefaultPieDataset();
    if (riskCount == 0) {
        title = "";
        piedataset.setValue(noVulnerabilities, new Integer(1));
    } else {//from   w w w. j  av  a2  s.  com
        piedataset.setValue(lowValue, new Integer(low));
        piedataset.setValue(mediumValue, new Integer(medium));
        piedataset.setValue(highValue, new Integer(high));
        piedataset.setValue(criticalValue, new Integer(critical));
    }

    JFreeChart piechart = ChartFactory.createPieChart(title, // Title  
            piedataset, // Dataset  
            true, // Show legend  
            true, // Use tooltips  
            false // Generate URLs  
    );

    PiePlot plot = (PiePlot) piechart.getPlot();
    //plot.setSimpleLabels(true); 
    if (riskCount == 0) {
        plot.setSectionPaint(noVulnerabilities, new Color(47, 196, 6));
        plot.setLabelLinksVisible(false);
        plot.setLabelGenerator(null);
        piechart.removeLegend();
    } else {
        plot.setSectionPaint(criticalValue, new Color(230, 27, 27));
        plot.setSectionPaint(highValue, new Color(230, 90, 27));
        plot.setSectionPaint(mediumValue, new Color(85, 144, 176));
        plot.setSectionPaint(lowValue, new Color(230, 219, 27));
    }

    if (isMain) {
        piechart.removeLegend();
    }
    plot.setBackgroundPaint(new Color(210, 234, 243));
    ChartPanel chartPanel = new ChartPanel(piechart);
    chartPanel.setEnabled(false);
    return chartPanel;
}

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

@SuppressWarnings("unchecked")
private void setColor(PiePlot plot, DefaultPieDataset dataset, Color[] colors) {
    List<Comparable> keys = dataset.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        plot.setSectionPaint(keys.get(i), colors[i]);
    }/*from   w  w  w.j av a  2 s.co m*/
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.SeriesColorsByNameCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
        CategoryDataset dataset = chart.getCategoryPlot().getDataset();
        Set<String> legend = new LinkedHashSet<String>();
        if (dataset != null) {
            for (int i = 0; i < dataset.getRowCount(); i++) {
                String key = (String) dataset.getRowKey(i);
                if (renderer instanceof GroupedStackedBarRenderer) {
                    key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
                    legend.add(key);//from w  w  w .j a  va  2  s .c o m
                }
                renderer.setSeriesPaint(i, seriesColorsByName.get(key));
            }
        }
        if (!legend.isEmpty()) {
            LegendItemCollection legendItems = new LegendItemCollection();
            for (String item : legend) {
                legendItems.add(new LegendItem(item, seriesColorsByName.get(item)));
            }
            chart.getCategoryPlot().setFixedLegendItems(legendItems);
        }
    } else if (chart.getPlot() instanceof PiePlot) {
        PiePlot plot = (PiePlot) chart.getPlot();
        PieDataset dataset = plot.getDataset();
        for (int i = 0; i < dataset.getItemCount(); i++) {
            String key = (String) dataset.getKey(i);
            plot.setSectionPaint(key, seriesColorsByName.get(key));
        }
    } else if (chart.getPlot() instanceof XYPlot) {
        XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        XYDataset dataset = chart.getXYPlot().getDataset();
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            String key = (String) dataset.getSeriesKey(i);
            renderer.setSeriesPaint(i, seriesColorsByName.get(key));
        }
    }
}

From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java

private void configureIndividualColors(PiePlot plot, PieDataset pieData) {
    int num = 1;//from w w  w.ja  va  2  s .c  om
    for (Object key : pieData.getKeys()) {
        String colorKey = "c" + num;
        String color = getParameter(colorKey);
        if (color != null)
            plot.setSectionPaint((Comparable) key, Color.decode("#" + color));
        num++;
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

/**
 * Create a simple pie chart without title, legend, label etc.
 * //from w  ww  .  jav a2  s.c  om
 * @param dataset
 *            the dataset to be renderer
 * @param colors
 *            an color array specify each item's color. The order of the
 *            array correspond to the item order in dataset
 * @return a pie chart
 */
public static JFreeChart createPlainPieChart(PieDataset dataset, Color[] colors) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }
    if (colors != null && colors.length != dataset.getItemCount()) {
        throw new IllegalArgumentException("Data have " + dataset.getItemCount() + " values, while we have "
                + colors.length + " colors for them.");
    }

    JFreeChart jfreechart = ChartFactory.createPieChart(null, dataset, false, true, false);
    PiePlot pieplot = (PiePlot) jfreechart.getPlot();
    if (colors != null) {
        for (int i = 0; i < colors.length; i++) {
            pieplot.setSectionPaint(dataset.getKey(i), colors[i]);
        }
    }
    pieplot.setBackgroundPaint(null);
    pieplot.setOutlineStroke(null);
    pieplot.setLabelGenerator(null);
    pieplot.setNoDataMessage(UILabels.STL40001_ERROR_No_DATA.getDescription());
    pieplot.setCircular(true);
    pieplot.setInteriorGap(0.000001);
    return jfreechart;
}

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

private JFreeChart createChart(String title, SessionSummary summary) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(Localization.get(LC.LEARNED), (int) summary.getPassed());
    dataset.setValue(Localization.get(LC.FAILED), (int) summary.getFailed());
    dataset.setValue(Localization.get(LC.SKIPPED), (int) summary.getSkipped());
    dataset.setValue(Localization.get(LC.RELEARNED), (int) summary.getRelearned());

    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setForegroundAlpha(0.5f);//www  .  j a  va2  s.c om
    plot.setIgnoreZeroValues(true);

    plot.setLabelFont(plot.getLabelFont().deriveFont(11f));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1} ({2})"));

    plot.setSectionPaint(Localization.get(LC.LEARNED), ColorConstants.LEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.FAILED), ColorConstants.EXPIRED_CARDS);
    plot.setSectionPaint(Localization.get(LC.SKIPPED), ColorConstants.UNLEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.RELEARNED), ColorConstants.RELEARNED_CARDS);

    return chart;
}

From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java

private void maybeConfigurePhaseColors(final PiePlot plot, PieDataset pieData) {
    ProcessUtil procUtil = new ProcessUtil(getDataContext());
    new PhaseChartColorer(procUtil, pieData.getKeys()) {
        public void setItemColor(Object key, int pos, Color c) {
            plot.setSectionPaint((Comparable) key, c);
        }/*www.  j  ava 2s.co m*/
    }.run();
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java

/**
 * sets the section colors of a pie chart to the passed color range.
 * // ww w .jav  a  2s .  c  o  m
 * @param plot a <code>PiePlot</code>
 * @param aColorRange an array of Colors, where each consequetive color is assigned to the next pie section.
 */
private void setPieColors(final PiePlot plot, final Color[] aColorRange) {
    for (int i = 0; i < aColorRange.length; i++) {
        plot.setSectionPaint(i, aColorRange[i]);
    }
}