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

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

Introduction

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

Prototype

public void setSectionPaint(Comparable key, Paint paint) 

Source Link

Document

Sets the paint associated with the specified key, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.chris.brkopani.gui.analytics.Graph.java

/**
 * * Creates a chart/*from  www.j  a  v a 2s .  c  o  m*/
 */
private JFreeChart createChart(PieDataset dataset, String title) {

    JFreeChart chart = ChartFactory.createPieChart3D(title, // chart title
            dataset, // data
            true, // include legend
            true, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setSectionPaint("...-20", new Color(195, 203, 113));
    plot.setSectionPaint("21-30", new Color(174, 90, 65));
    plot.setSectionPaint("35-...", new Color(85, 158, 131));
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    return chart;

}

From source file:draw.charts.PieRenderer.java

/**
 * Iterates through the Pie dataset keys and assigns proper colors to their
 * segments.//from  ww  w  .java 2s. c o m
 *
 * @param plot PiePlot3D object.
 * @param dataset DefaultPieDataset that the charts is drawn from.
 */
public void setColor(PiePlot3D 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.uttesh.pdfngreport.handler.PdfReportHandler.java

/**
 * This method will generate the chart image file by using the Jfree chart
 * library/* w w  w .  java 2  s . com*/
 *
 * @param dataSet
 * @throws FileNotFoundException
 * @throws IOException
 *
 * @see DefaultPieDataset
 */
public void generateChart(DefaultPieDataset dataSet, String os) throws FileNotFoundException, IOException {
    try {
        JFreeChart chart = ChartFactory.createPieChart3D("", dataSet, true, true, false);
        ChartStyle.theme(chart);
        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setForegroundAlpha(0.6f);
        plot.setCircular(true);
        plot.setSectionPaint("Passed", Color.decode("#019244"));
        plot.setSectionPaint("Failed", Color.decode("#EE6044"));
        plot.setSectionPaint("Skipped", Color.decode("#F0AD4E"));
        Color transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
        plot.setLabelOutlinePaint(transparent);
        plot.setLabelBackgroundPaint(transparent);
        plot.setLabelShadowPaint(transparent);
        plot.setLabelLinkPaint(Color.GRAY);
        Font font = new Font("SansSerif", Font.PLAIN, 10);
        plot.setLabelFont(font);
        PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
                new DecimalFormat("0"), new DecimalFormat("0%"));
        plot.setLabelGenerator(gen);
        if (os != null && os.equalsIgnoreCase("w")) {
            ChartUtilities.saveChartAsPNG(
                    new File(reportLocation + Constants.BACKWARD_SLASH + Constants.REPORT_CHART_FILE), chart,
                    560, 200);
        } else {
            ChartUtilities.saveChartAsPNG(
                    new File(reportLocation + Constants.FORWARD_SLASH + Constants.REPORT_CHART_FILE), chart,
                    560, 200);
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
        if (os != null && os.equalsIgnoreCase("w")) {
            new File(reportLocation + Constants.BACKWARD_SLASH + Constants.REPORT_CHART_FILE).delete();
        } else {
            new File(reportLocation + Constants.FORWARD_SLASH + Constants.REPORT_CHART_FILE).delete();
        }
        System.exit(-1);
    }
}

From source file:net.nosleep.superanalyzer.analysis.views.RatingView.java

private void refreshDataset() {
    _dataset.clear();/*  www. ja v  a  2  s .  co  m*/

    Stat itemStats = null;

    if (_comboBox == null) {
        itemStats = _analysis.getStats(Analysis.KIND_TRACK, null);
    } else {
        ComboItem item = (ComboItem) _comboBox.getSelectedItem();
        itemStats = _analysis.getStats(item.getKind(), item.getValue());
    }

    Vector<Double> counts = new Vector<Double>(6);
    double[] ratings = itemStats.getRatings();
    for (int i = 0; i < ratings.length; i++)
        counts.addElement(new Double(ratings[i]));

    Vector<String> labels = new Vector<String>(6);
    labels.add(new String(Misc.getString("NOT_RATED")));
    labels.add(new String("1 " + Misc.getString("STAR")));
    labels.add(new String("2 " + Misc.getString("STARS")));
    labels.add(new String("3 " + Misc.getString("STARS")));
    labels.add(new String("4 " + Misc.getString("STARS")));
    labels.add(new String("5 " + Misc.getString("STARS")));

    PiePlot3D plot = (PiePlot3D) _chart.getPlot();
    Color[] colors = Theme.getColorSet();
    plot.setIgnoreZeroValues(true);

    for (int i = 0; i < counts.size(); i++) {
        // if((Double)counts.elementAt(i) > 0)
        {
            _dataset.setValue((String) labels.elementAt(i), (Double) counts.elementAt(i));
            plot.setSectionPaint((String) labels.elementAt(i), colors[5 - i]);
        }
    }

}

From source file:net.nosleep.superanalyzer.analysis.views.QualityView.java

private void refreshDataset() {

    Stat itemStats = null;//from   www  . j av  a2 s  .  c  om

    if (_comboBox == null) {
        itemStats = _analysis.getStats(Analysis.KIND_TRACK, null);
    } else {
        ComboItem item = (ComboItem) _comboBox.getSelectedItem();
        itemStats = _analysis.getStats(item.getKind(), item.getValue());
    }

    Vector counts = new Vector(5);
    int[] rates = itemStats.getBitRates();
    for (int i = 0; i < rates.length; i++)
        counts.addElement(new Double(rates[i]));

    Vector labels = new Vector(5);
    labels.add(new String(Misc.getString("POOR") + "\n(0-63 kbps)\n"));
    labels.add(new String(Misc.getString("LOW") + "\n(64-127 kbps)\n"));
    labels.add(new String(Misc.getString("GOOD") + "\n(128-191 kbps)\n"));
    labels.add(new String(Misc.getString("HIGH") + "\n(192-255 kbps)\n"));
    labels.add(new String(Misc.getString("EXCELLENT") + "\n(256-320 kbps)\n"));

    _dataset.clear();

    PiePlot3D plot = (PiePlot3D) _chart.getPlot();
    Color[] colors = Theme.getColorSet();
    plot.setIgnoreZeroValues(true);

    for (int i = 0; i < counts.size(); i++) {
        // if((Double)counts.elementAt(i) > 0)
        {
            _dataset.setValue((String) labels.elementAt(i), (Double) counts.elementAt(i));
            plot.setSectionPaint((String) labels.elementAt(i), colors[5 - i]);
        }

    }

}

From source file:org.cyberoam.iview.charts.CustomToolTipGeneratorForDiskUsage.java

/**
 * This method generates JFreeChart instance for 3D Pie chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @return jfreechart instance with iView Customization.
 *///from w w w .  j  a va2s .c  om
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    boolean xFlag = false;
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    try {
        ReportColumnBean reportColumnBean, reportColumnBeanX = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        DefaultPieDataset dataset = new DefaultPieDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        //   String xColumnDBname = reportColumnBeanX.getDbColumnName();

        if (reportColumnBeanX.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        rsw.beforeFirst();
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnName = reportColumnBean.getColumnName();
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        String xData = null;
        while (rsw.next()) {
            xData = rsw.getString(reportColumnBeanX.getDbColumnName());
            if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData)) {
                xData = "N/A";
            } else if (reportColumnBeanX.getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING
                    && xData.indexOf(':') != -1) {
                String data = data = ProtocolBean.getProtocolNameById(Integer.parseInt(
                        rsw.getString(reportColumnBeanX.getDbColumnName()).substring(0, xData.indexOf(':'))));
                xData = data + rsw.getString(reportColumnBeanX.getDbColumnName()).substring(xData.indexOf(':'),
                        xData.length());
            }
            dataset.setValue(xData, new Long(rsw.getLong(reportColumnBean.getDbColumnName())));
        }
        chart = ChartFactory.createPieChart3D("", // chart title
                dataset, // data
                true, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         *Setting additional customization to the chart. 
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        //Get a reference to the plot for further customisation...
        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setBackgroundAlpha(0.0f);
        plot.setSectionOutlinesVisible(false);
        plot.setOutlineVisible(false);
        plot.setStartAngle(290);
        plot.setDepthFactor(0.1);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setNoDataMessage("No data to display");
        plot.setSectionOutlinesVisible(false);
        plot.setSectionOutlinePaint(Color.white);
        plot.setOutlineVisible(false);
        plot.setExplodePercent(dataset.getKey(0), 0.3);

        plot.setLabelLinkPaint(Color.gray);
        plot.setLabelBackgroundPaint(Color.white);
        plot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        plot.setLabelOutlinePaint(Color.white);
        plot.setLabelShadowPaint(Color.white);

        LegendTitle legend = chart.getLegend();
        legend.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        legend.setMargin(0, 0, 2, 0);
        legend.setHorizontalAlignment(HorizontalAlignment.CENTER);

        plot.setToolTipGenerator(new CustomToolTipGeneratorForPie3D("{0}: ({1} " + yColumnName + ", {2})"));
        //Setting Color 
        try {
            plot.setSectionPaint(dataset.getKey(0), new Color(0, 0, 254));
            plot.setSectionPaint(dataset.getKey(1), new Color(255, 0, 254));
            plot.setSectionPaint(dataset.getKey(2), new Color(176, 176, 255));
            plot.setSectionPaint(dataset.getKey(3), new Color(255, 170, 255));
            plot.setSectionPaint(dataset.getKey(4), new Color(69, 153, 204));
        } catch (Exception e) {
        }

    } catch (Exception e) {
        CyberoamLogger.appLog.debug("Pie3D.e:" + e, e);
    }
    return chart;
}

From source file:org.cyberoam.iview.charts.CustomToolTipGeneratorForPie3D.java

/**
 * This method generates JFreeChart instance for 3D Pie chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @return jfreechart instance with iView Customization.
 *//*from   ww w .j  ava  2 s .  co m*/
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    boolean xFlag = false;
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    try {
        ReportColumnBean reportColumnBean, reportColumnBeanX = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        DefaultPieDataset dataset = new DefaultPieDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        //   String xColumnDBname = reportColumnBeanX.getDbColumnName();

        if (reportColumnBeanX.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        rsw.beforeFirst();
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnName = reportColumnBean.getColumnName();
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        String xData = null;
        while (rsw.next()) {
            xData = rsw.getString(reportColumnBeanX.getDbColumnName());
            if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData)) {
                xData = "N/A";
            } else if (reportColumnBeanX.getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING
                    && xData.indexOf(':') != -1) {
                String data = data = ProtocolBean.getProtocolNameById(Integer.parseInt(
                        rsw.getString(reportColumnBeanX.getDbColumnName()).substring(0, xData.indexOf(':'))));
                xData = data + rsw.getString(reportColumnBeanX.getDbColumnName()).substring(xData.indexOf(':'),
                        xData.length());
            }
            dataset.setValue(xData, new Long(rsw.getLong(reportColumnBean.getDbColumnName())));
        }
        chart = ChartFactory.createPieChart3D("", // chart title
                dataset, // data
                true, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         *Setting additional customization to the chart. 
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        //Get a reference to the plot for further customisation...
        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setBackgroundAlpha(0.0f);
        plot.setSectionOutlinesVisible(false);
        plot.setOutlineVisible(false);
        plot.setStartAngle(290);
        plot.setDepthFactor(0.1);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setNoDataMessage("No data to display");
        plot.setSectionOutlinesVisible(false);
        plot.setSectionOutlinePaint(Color.white);
        plot.setOutlineVisible(false);
        plot.setExplodePercent(dataset.getKey(0), 0.3);

        plot.setLabelLinkPaint(Color.gray);
        plot.setLabelBackgroundPaint(Color.white);
        plot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        plot.setLabelOutlinePaint(Color.white);
        plot.setLabelShadowPaint(Color.white);

        LegendTitle legend = chart.getLegend();
        legend.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        legend.setMargin(0, 0, 2, 0);
        legend.setHorizontalAlignment(HorizontalAlignment.CENTER);

        plot.setToolTipGenerator(new CustomToolTipGeneratorForPie3D("{0}: ({1} " + yColumnName + ", {2})"));
        //Setting Color 
        try {
            plot.setSectionPaint(dataset.getKey(0), Pie3D.pieSections[0]);
            plot.setSectionPaint(dataset.getKey(1), Pie3D.pieSections[1]);
            plot.setSectionPaint(dataset.getKey(2), Pie3D.pieSections[2]);
            plot.setSectionPaint(dataset.getKey(3), Pie3D.pieSections[3]);
            plot.setSectionPaint(dataset.getKey(4), Pie3D.pieSections[4]);
        } catch (Exception e) {
        }

    } catch (Exception e) {
        CyberoamLogger.appLog.debug("Pie3D.e:" + e, e);
    }
    return chart;
}

From source file:com.esofthead.mycollab.community.ui.chart.PieChartWrapper.java

@Override
protected JFreeChart createChart() {
    // create the chart...
    pieDataSet = createDataset();/*from w  ww  .j a  v a  2 s  . c  om*/
    final JFreeChart chart = ChartFactory.createPieChart3D("", // chart
            // title
            pieDataSet, // data
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.getTitle().setPaint(new Color(0x5E5E5E));
    chart.setBorderVisible(false);
    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setStartAngle(290);
    plot.setBackgroundPaint(Color.white);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");
    plot.setLabelGenerator(new JFreeChartLabelCustom());

    final List keys = pieDataSet.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        final Comparable key = (Comparable) keys.get(i);
        plot.setSectionPaint(key, Color.decode(
                "0x" + GenericChartWrapper.CHART_COLOR_STR[i % GenericChartWrapper.CHART_COLOR_STR.length]));
    }
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:com.estate.pdf.Page.java

protected void drawTaxPie(Rectangle rct, double totalValue, double tax, String taxLabel, String netLabel) {
    double taxPercent = (tax / totalValue) * 100;
    double netValuePercent = 100 - taxPercent;

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(taxLabel, taxPercent);
    dataset.setValue(netLabel, netValuePercent);

    PiePlot3D plot = new PiePlot3D(dataset);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator());
    plot.setInsets(new Insets(0, 5, 5, 5));
    plot.setToolTipGenerator(new CustomeGenerators.CustomToolTipGenerator());
    plot.setLabelGenerator(new CustomeGenerators.CustomLabelGenerator());
    plot.setSectionPaint(0, new Color(pgRed));
    plot.setSectionPaint(1, new Color(pgGreen));
    plot.setForegroundAlpha(.6f);/*from  ww  w .ja  va  2  s .  c  o m*/
    plot.setOutlinePaint(Color.white);
    plot.setBackgroundPaint(Color.white);

    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);

    Rectangle page = rct;

    try {
        Image img = Image.getInstance(chart.createBufferedImage((int) page.getWidth(), (int) page.getHeight()),
                null);
        drawDiagram(img, rct, 0, 72);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}

From source file:com.esofthead.mycollab.ui.chart.PieChartWrapper.java

@Override
protected JFreeChart createChart() {
    // create the chart...
    pieDataSet = createDataset();/* w  w w  .  jav  a2  s .co m*/
    final JFreeChart chart = ChartFactory.createPieChart3D("", // chart
            // title
            pieDataSet, // data
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.getTitle().setPaint(new Color(0x5E5E5E));
    chart.setBorderVisible(false);
    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setStartAngle(290);
    plot.setBackgroundPaint(Color.white);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");
    plot.setLabelGenerator(new JFreeChartLabelCustom());

    final List keys = pieDataSet.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        final Comparable key = (Comparable) keys.get(i);
        int colorIndex = i % CHART_COLOR_STR.size();
        plot.setSectionPaint(key, Color.decode("0x" + CHART_COLOR_STR.get(colorIndex)));
    }
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}