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

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

Introduction

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

Prototype

public void setLabelLinkPaint(Paint paint) 

Source Link

Document

Sets the paint used for the lines that connect pie sections to their corresponding labels, and sends a PlotChangeEvent to all registered listeners.

Usage

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 . ja  v  a  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), 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   w ww  . j  a v a2 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.uttesh.pdfngreport.handler.PdfReportHandler.java

/**
 * This method will generate the chart image file by using the Jfree chart
 * library/* w  w  w .  j ava 2  s.c o  m*/
 *
 * @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:com.pureinfo.srm.reports.impl.PieChartBuilder.java

/**
 * @throws PureException//from w w  w.  java  2s .  com
 * @see com.pureinfo.srm.reports.IChartBuilder#draw(java.util.List, int)
 */
public JFreeChart buildChart() {
    Iterator result = m_datas.iterator();
    DefaultPieDataset ds = getDataset(result);

    JFreeChart jfreechart = ChartFactory.createPieChart3D(null, ds, false, false, false);
    jfreechart.setBackgroundPaint(Color.WHITE);

    PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
    pieplot3d.setOutlinePaint(Color.GRAY);
    pieplot3d.setOutlineStroke(new BasicStroke(1));
    pieplot3d.setStartAngle(30D);
    pieplot3d.setDepthFactor(0.04);
    pieplot3d.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));

    pieplot3d.setCircular(false);
    pieplot3d.setDirection(Rotation.CLOCKWISE);
    pieplot3d.setOutlinePaint(Color.WHITE);
    pieplot3d.setInteriorGap(.15);
    Color color = new Color(0xaa, 0xaa, 0xaa, 255);
    pieplot3d.setBaseSectionOutlinePaint(color);
    pieplot3d.setBaseSectionOutlineStroke(new BasicStroke(0));
    pieplot3d.setForegroundAlpha(0.6f);
    pieplot3d.setLabelLinkStroke(new BasicStroke(1));
    pieplot3d.setLabelOutlinePaint(new Color(0x777777));
    pieplot3d.setLabelBackgroundPaint(new Color(0xf1f1f7));
    pieplot3d.setLabelLinkPaint(new Color(0xaa, 0xaa, 0xaa, 60));
    pieplot3d.setNoDataMessage("No data to display");
    pieplot3d.setLabelShadowPaint(new Color(0xdddddd));
    pieplot3d.setLabelFont(new Font("", Font.PLAIN, 10));
    if (m_nType == TYPE_PERCENT) {

        pieplot3d.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}",
                NumberFormat.getNumberInstance(), PERCENT_NUMBER_FORMAT));
    }

    fillChartInfo(ds);
    return jfreechart;
}