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

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

Introduction

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

Prototype

public void setNoDataMessage(String message) 

Source Link

Document

Sets the message that is displayed when the dataset is empty or null, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.ikon.servlet.admin.StatsGraphServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String action = WebUtils.getString(request, "action", "graph");
    String type = WebUtils.getString(request, "t");
    JFreeChart chart = null;//from   www  .j a va2 s  .c o  m
    updateSessionManager(request);

    try {
        if ("refresh".equals(action)) {
            new RepositoryInfo().runAs(null);
            ServletContext sc = getServletContext();
            sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
        } else {
            response.setContentType("image/png");
            OutputStream out = response.getOutputStream();

            if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
                chart = repoStats(type);
            } else if (DISK.equals(type)) {
                chart = diskStats();
            } else if (JVM_MEMORY.equals(type)) {
                chart = jvmMemStats();
            } else if (OS_MEMORY.equals(type)) {
                chart = osMemStats();
            }

            if (chart != null) {
                // Customize title font
                chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));

                // Match body {   background-color:#F6F6EE; }
                chart.setBackgroundPaint(new Color(246, 246, 238));

                // Customize no data
                PiePlot plot = (PiePlot) chart.getPlot();
                plot.setNoDataMessage("No data to display");

                // Customize labels
                plot.setLabelGenerator(null);

                // Customize legend
                LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
                legend.setPosition(RectangleEdge.BOTTOM);
                legend.setFrame(BlockBorder.NONE);
                legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
                chart.removeLegend();
                chart.addLegend(legend);

                if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
                    ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
                } else {
                    ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
                }
            }

            out.flush();
            out.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:uk.ac.bbsrc.tgac.miso.core.util.ReportsUtils.java

public static String buildHTMLReport(List<? extends Reportable> reportables, String type, List<String> options)
        throws ReportingException {
    Random generator = new Random();
    StringBuilder sb = new StringBuilder();
    Boolean chartbool = false;/*  www  .ja  v  a  2 s.co  m*/
    if (options.contains("Chart")) {
        chartbool = true;
    }

    // header
    sb.append(
            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
                    + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
                    + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-gb\">\n" + "<head>\n"
                    + "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n"
                    + "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n"
                    + "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\n"
                    + "<meta http-equiv=\"Expires\" content=\"Sat, 01 Dec 2001 00:00:00 GMT\">\n"
                    + "    <link rel=\"stylesheet\" href=\"/styles/style.css\" type=\"text/css\">\n"
                    + "<title>MISO Report</title>"
                    + "</head><body onLoad=\"self.focus()\"><table border=\"0\" width=\"100%\">\n"
                    + "    <tr>\n" + "        <td class=\"headertable\" align=\"left\" \">\n"
                    + "            <img src=\"/styles/images/miso_logo.png\" alt=\"MISO Logo\" name=\"logo\"\n"
                    + "                                  border=\"0\" id=\"misologo\"/>\n" + "        </td>\n"
                    + "        <td class=\"headertable\" align=\"right\" \">\n"
                    + "            <img src=\"/styles/images/tgac_new_logo.png\" alt=\"TGAC Logo\" name=\"logo\"\n"
                    + "                                  border=\"0\" id=\"tgaclogo\"/>\n" + "        </td>\n"
                    + "    </tr>\n" + "</table><hr/>");
    // end of header

    if (type.equals("Project")) {
        Boolean incOverview = false;
        Boolean incSamples = false;
        if (options.contains("Overview")) {
            incOverview = true;
        }
        if (options.contains("Samples")) {
            incSamples = true;
        }

        if (reportables.size() == 1) {
            //Single Project report
            List reportableslist = new ArrayList<Reportable>(reportables);
            Reportable reportable = (Reportable) reportableslist.get(0);
            Project project = (Project) reportable;
            sb.append("<h1>Project Information</h1><br/><div class='report'>");
            sb.append("<b>Project Name: </b> " + project.getName());
            sb.append("<br/><br/>");
            sb.append("<b>Project Alias: </b> " + project.getAlias());
            sb.append("<br/><br/>");
            sb.append("<b>Project Description: </b> " + project.getDescription());
            sb.append("<br/><br/>");
            sb.append("<b>Progress: </b> " + project.getProgress().name());
            sb.append("<br/><br/>");

            if (project.getOverviews().size() > 0 && incOverview) {
                sb.append("<table class=\"list\">\n" + "            <thead>\n" + "            <tr>\n"
                        + "                <th>Principal Investigator</th>\n"
                        + "                <th>Start Date</th>\n" + "                <th>End Date</th>\n"
                        + "                <th>Proposed Samples</th>\n"
                        + "                <th>QC Passed Sample</th>\n" + "            </tr>\n"
                        + "            </thead>\n" + "            <tbody>");
                for (ProjectOverview overview : project.getOverviews()) {
                    sb.append("<tr>\n" + "                    <td>" + overview.getPrincipalInvestigator()
                            + "</td>\n" + "                    <td>" + overview.getStartDate() + "</td>\n"
                            + "                    <td>" + overview.getEndDate() + "</td>\n"
                            + "                    <td>" + overview.getNumProposedSamples().toString()
                            + "</td>\n" + "                    <td>" + overview.getQcPassedSamples().size()
                            + "</td>\n" + "                </tr>");
                }
                sb.append("</tbody>\n" + "        </table>");
            } else {
                if (incOverview) {
                    sb.append("<b>Overview:</b> None.");
                }
            }
            sb.append("<br/>");
            if (project.getSamples().size() > 0 && incSamples) {
                sb.append("<table class=\"list\">\n" + "            <thead>\n" + "            <tr>\n"
                        + "                <th>Sample Name</th>\n" + "                <th>Sample Alias</th>\n"
                        + "                <th>Type</th>\n" + "                <th>QC Passed</th>\n"
                        + "            </tr>\n" + "            </thead>\n" + "            <tbody>");
                for (Sample sample : project.getSamples()) {
                    sb.append("<tr>\n" + "                    <td><b>" + sample.getName() + "</b></td>\n"
                            + "                    <td>" + sample.getAlias() + "</td>\n"
                            + "                    <td>" + sample.getSampleType() + "</td>\n"
                            + "                    <td>" + sample.getQcPassed().toString() + "</td>\n"
                            + "                </tr>");
                }
                sb.append("</tbody>\n" + "        </table>");
            } else {
                if (incSamples) {
                    sb.append("<b>Samples:</b> None.");
                }
            }

        }
        // Lists of Projects report
        else if (reportables.size() > 1) {
            sb.append("<h1>Projects Information</h1><br/><div class='report'>");
            Map<String, Integer> map = new HashMap<String, Integer>();
            sb.append("<table class=\"list\">\n" + "    <thead>\n" + "    <tr>\n"
                    + "        <th>Project Name</th>\n" + "        <th>Project Alias</th>\n"
                    + "        <th>Project Description</th>\n" + "        <th>Progress</th>\n");
            if (incOverview) {
                sb.append("        <th>Overviews</th>\n");
            }
            if (incSamples) {
                sb.append("        <th>Samples</th>\n");
            }
            sb.append("    </tr>\n" + "    </thead>\n" + "    <tbody>");
            for (Reportable reportable : reportables) {
                Project project = (Project) reportable;
                sb.append("<tr><td>" + project.getName());
                sb.append("</td>");
                sb.append("<td> " + project.getAlias());
                sb.append("</td>");
                sb.append("<td> " + project.getDescription());
                sb.append("</td>");
                sb.append("<td> " + project.getProgress().name());
                sb.append("</td>");
                if (incOverview) {
                    sb.append("<td>");
                    if (project.getOverviews().size() > 0) {
                        sb.append("<ul class='bullets'>");
                        for (ProjectOverview overview : project.getOverviews()) {
                            sb.append("<li>Principal Investigator: " + overview.getPrincipalInvestigator()
                                    + "<br/> Start Date: " + overview.getStartDate() + "<br/> End Date: "
                                    + overview.getEndDate() + "<br/> Proposed Samples: "
                                    + overview.getNumProposedSamples().toString() + "<br/> QC Passed Samples: "
                                    + overview.getQcPassedSamples().size() + "</li>");
                        }
                        sb.append("</ul>");
                    } else {
                        sb.append("None");
                    }
                    sb.append("</td>");
                }
                if (incSamples) {
                    sb.append("<td>");
                    if (project.getSamples().size() > 0) {
                        sb.append("<ul class='bullets'>");
                        for (Sample sample : project.getSamples()) {
                            sb.append("<li>" + sample.getAlias() + "</li>");
                        }
                        sb.append("</ul>");
                    } else {
                        sb.append("None");
                    }
                    sb.append("</td>");
                }
                sb.append("</tr>");
                int count = map.containsKey(project.getProgress().getKey())
                        ? map.get(project.getProgress().getKey())
                        : 0;
                count++;
                map.put(project.getProgress().getKey(), count);
            }
            sb.append("    </tbody>\n" + "</table>");
            Integer unknown = map.containsKey("Unknown") ? map.get("Unknown") : 0;
            Integer active = map.containsKey("Active") ? map.get("Active") : 0;
            Integer inactive = map.containsKey("Inactive") ? map.get("Inactive") : 0;
            Integer cancelled = map.containsKey("Cancelled") ? map.get("Cancelled") : 0;
            Integer proposed = map.containsKey("Proposed") ? map.get("Proposed") : 0;
            Integer pending = map.containsKey("Pending") ? map.get("Pending") : 0;
            Integer approved = map.containsKey("Approved") ? map.get("Approved") : 0;
            Integer completed = map.containsKey("Completed") ? map.get("Completed") : 0;
            //jfreechart
            final DefaultPieDataset data = new DefaultPieDataset();
            data.setValue("Unknown " + unknown, unknown);
            data.setValue("Active " + active, active);
            data.setValue("Inactive " + inactive, inactive);
            data.setValue("Cancelled " + cancelled, cancelled);
            data.setValue("Proposed " + proposed, proposed);
            data.setValue("Pending " + pending, pending);
            data.setValue("Approved " + approved, approved);
            data.setValue("Completed " + completed, completed);

            final JFreeChart chart = ChartFactory.createPieChart("Projects Status Information", // chart title
                    data, // data
                    false, // include legend
                    true, false);

            final PiePlot plot = (PiePlot) chart.getPlot();
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setBackgroundPaint(Color.white);
            plot.setForegroundAlpha(0.5f);
            plot.setNoDataMessage("No data to display");
            int r = generator.nextInt();
            File projectchart = new File("../webapps/ROOT/styles/images/projectschart" + r + ".png");
            try {
                ChartUtilities.saveChartAsPNG(projectchart, chart, 500, 300);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (chartbool) {
                sb.append("<br/><img src='/styles/images/projectschart" + r + ".png'/>");
            }
        } else {
            sb.append("<h1>Project Information</h1><br/><div class='report'>Nothing to Report.");
        }

    } else if (type.equals("Sample")) {
        Boolean incQC = false;
        if (options.contains("QC")) {
            incQC = true;
        }

        if (reportables.size() == 1) {
            //Single Sample report
            List reportableslist = new ArrayList<Reportable>(reportables);
            Reportable reportable = (Reportable) reportableslist.get(0);
            Sample sample = (Sample) reportable;
            sb.append("<h1>Sample Information</h1><br/><div class='report'>");
            sb.append("<b>Sample Name: </b> " + sample.getName());
            sb.append("<br/><br/>");
            sb.append("<b>Project Alias: </b> " + sample.getProject().getAlias());
            sb.append("<br/><br/>");
            sb.append("<b>Sample Alias: </b> " + sample.getAlias());
            sb.append("<br/><br/>");
            sb.append("<b>Sample Description: </b> " + sample.getDescription());
            sb.append("<br/><br/>");
            sb.append("<b>Scientific Name: </b> " + sample.getScientificName());
            sb.append("<br/><br/>");
            sb.append("<b>Sample Type: </b> " + sample.getSampleType());
            sb.append("<br/><br/>");
            sb.append("<b>QC Passed: </b> " + sample.getQcPassed().toString());
            sb.append("<br/><br/>");

            if (sample.getSampleQCs().size() > 0 && incQC) {
                sb.append("<table class=\"list\">\n" + "            <thead>\n" + "            <tr>\n"
                        + "                <th>QCed By</th>\n" + "                <th>QC Date</th>\n"
                        + "                <th>Method</th>\n" + "                <th>Results</th>\n"
                        + "            </tr>\n" + "            </thead>\n" + "            <tbody>");
                for (SampleQC sampleQC : sample.getSampleQCs()) {
                    sb.append("<tr>\n" + "                    <td>" + sampleQC.getQcCreator() + "</td>\n"
                            + "                    <td>" + sampleQC.getQcDate().toString() + "</td>\n"
                            + "                    <td>" + sampleQC.getQcType().getName() + "</td>\n"
                            + "                    <td>" + sampleQC.getResults().toString()
                            + "ng/&#181;l</td>\n" + "                </tr>");
                }
                sb.append("</tbody>\n" + "        </table>");
            } else {
                if (incQC) {
                    sb.append("<b>QC:</b> None.");
                }
            }

        }
        // Lists of Samples report
        else if (reportables.size() > 1) {
            sb.append("<h1>Samples Information</h1><br/><div class='report'>");
            Map<String, Integer> typeMap = new HashMap<String, Integer>();
            Map<String, Integer> qcMap = new HashMap<String, Integer>();
            sb.append("<table class=\"list\">\n" + "    <thead>\n" + "    <tr>\n"
                    + "        <th>Sample Name</th>\n" + "        <th>Project Alias</th>\n"
                    + "        <th>Sample Alias</th>\n" + "        <th>Sample Description</th>\n"
                    + "        <th>Scientific Name</th>\n" + "        <th>Sample Type</th>\n"
                    + "        <th>QC Passed</th>\n");
            if (incQC) {
                sb.append("        <th>QC</th>\n");
            }
            sb.append("    </tr>\n" + "    </thead>\n" + "    <tbody>");
            for (Reportable reportable : reportables) {
                Sample sample = (Sample) reportable;
                sb.append("<tr><td>" + sample.getName());
                sb.append("</td>");
                sb.append("<td>" + sample.getProject().getAlias());
                sb.append("</td>");
                sb.append("<td> " + sample.getAlias());
                sb.append("</td>");
                sb.append("<td> " + sample.getDescription());
                sb.append("</td>");
                sb.append("<td> " + sample.getScientificName());
                sb.append("</td>");
                sb.append("<td> " + sample.getSampleType());
                sb.append("</td>");
                sb.append("<td> " + sample.getQcPassed().toString());
                sb.append("</td>");
                if (incQC) {
                    sb.append("<td>");
                    if (sample.getSampleQCs().size() > 0) {
                        sb.append("<ul class='bullets'>");
                        for (SampleQC sampleQC : sample.getSampleQCs()) {
                            sb.append("<li>\n" + "                    QCed By: " + sampleQC.getQcCreator()
                                    + "<br/>\n" + "                    QC Date: "
                                    + sampleQC.getQcDate().toString() + "<br/>\n"
                                    + "                    Method: " + sampleQC.getQcType().getName()
                                    + "<br/>\n" + "                    Results: "
                                    + sampleQC.getResults().toString() + "ng/&#181;l</li>");
                        }
                        sb.append("</ul>");
                    } else {
                        sb.append("None");
                    }
                    sb.append("</td>");
                }
                sb.append("</tr>");

                int typecount = typeMap.containsKey(sample.getSampleType())
                        ? typeMap.get(sample.getSampleType())
                        : 0;
                typecount++;
                typeMap.put(sample.getSampleType(), typecount);

                int qccount = qcMap.containsKey(sample.getQcPassed().toString())
                        ? qcMap.get(sample.getQcPassed().toString())
                        : 0;
                qccount++;
                qcMap.put(sample.getQcPassed().toString(), qccount);
            }
            sb.append("    </tbody>\n" + "</table>");
            Integer nonGENOMIC = typeMap.containsKey("NON GENOMIC") ? typeMap.get("NON GENOMIC") : 0;
            Integer genomic = typeMap.containsKey("GENOMIC") ? typeMap.get("GENOMIC") : 0;
            Integer other = typeMap.containsKey("OTHER") ? typeMap.get("OTHER") : 0;
            Integer viralRNA = typeMap.containsKey("VIRAL RNA") ? typeMap.get("VIRAL RNA") : 0;
            Integer synthetic = typeMap.containsKey("SYNTHETIC") ? typeMap.get("SYNTHETIC") : 0;

            //jfreechart for type
            final DefaultPieDataset data = new DefaultPieDataset();
            data.setValue("NON GENOMIC " + nonGENOMIC, nonGENOMIC);
            data.setValue("GENOMIC " + genomic, genomic);
            data.setValue("OTHER " + other, other);
            data.setValue("VIRAL RNA " + viralRNA, viralRNA);
            data.setValue("SYNTHETIC " + synthetic, synthetic);

            final JFreeChart chart = ChartFactory.createPieChart("Samples Type Information", // chart title
                    data, // data
                    false, // include legend
                    true, false);

            final PiePlot plot = (PiePlot) chart.getPlot();
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setForegroundAlpha(0.5f);
            plot.setBackgroundPaint(Color.white);
            plot.setNoDataMessage("No data to display");
            int r = generator.nextInt();
            File samplechart = new File("../webapps/ROOT/styles/images/samplestypechart" + r + ".png");
            try {
                ChartUtilities.saveChartAsPNG(samplechart, chart, 500, 300);
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (chartbool) {
                sb.append("<br/><img src='/styles/images/samplestypechart" + r + ".png'/>");
            }
            Integer qcpassed = qcMap.containsKey("true") ? qcMap.get("true") : 0;
            Integer qcnotpassed = qcMap.containsKey("false") ? qcMap.get("false") : 0;

            //jfreechart for qc
            final DefaultPieDataset qcdata = new DefaultPieDataset();
            qcdata.setValue("QC Passed " + qcpassed, qcpassed);
            qcdata.setValue("QC Not Passed " + qcnotpassed, qcnotpassed);

            final JFreeChart qcchart = ChartFactory.createPieChart("Samples QC Information", // chart title
                    qcdata, // data
                    false, // include legend
                    true, false);

            final PiePlot qcplot = (PiePlot) qcchart.getPlot();
            qcplot.setStartAngle(290);
            qcplot.setDirection(Rotation.CLOCKWISE);
            qcplot.setForegroundAlpha(0.5f);
            qcplot.setBackgroundPaint(Color.white);
            qcplot.setNoDataMessage("No data to display");
            File sampleqcchart = new File("../webapps/ROOT/styles/images/samplesqcchart" + r + ".png");
            try {
                ChartUtilities.saveChartAsPNG(sampleqcchart, qcchart, 500, 300);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (chartbool) {
                sb.append(" <img src='/styles/images/samplesqcchart" + r + ".png'/>");
            }
        } else {
            sb.append("<h1>Sample Information</h1><br/><div class='report'>Nothing to Report.");
        }

    } else if (type.equals("Run")) {
        Boolean incAlias = false;
        Boolean incDescription = false;
        if (options.contains("Alias")) {
            incAlias = true;
        }
        if (options.contains("Description")) {
            incDescription = true;
        }

        if (reportables.size() == 1) {
            //Single Run report
            List reportableslist = new ArrayList<Reportable>(reportables);
            Reportable reportable = (Reportable) reportableslist.get(0);
            Run run = (Run) reportable;
            sb.append("<h1>Run Information</h1><br/><div class='report'>");
            sb.append("<b>Run Name: </b> " + run.getName());
            sb.append("<br/><br/>");
            sb.append("<b>Platform: </b> " + run.getPlatformType().getKey());
            sb.append("<br/><br/>");
            sb.append("<b>Sequencer: </b> " + run.getSequencerReference().getName());
            sb.append("<br/><br/>");
            if (incAlias) {
                sb.append("<b>Run Alias: </b> " + run.getAlias());
                sb.append("<br/><br/>");
            }
            if (incDescription) {
                sb.append("<b>Run Description: </b> " + run.getDescription());
                sb.append("<br/><br/>");
            }
            sb.append("<b>Pair End: </b> " + run.getPairedEnd().toString());
            sb.append("<br/><br/>");
            sb.append("<b>Status: </b> " + run.getStatus().getHealth().getKey());
            sb.append("<br/><br/>");

        }
        // Lists of Runs report
        else if (reportables.size() > 1) {
            sb.append("<h1>Runs Information</h1><br/><div class='report'>");
            Map<String, Integer> statusMap = new HashMap<String, Integer>();
            Map<String, Integer> platformMap = new HashMap<String, Integer>();
            sb.append(
                    "<table class=\"list\">\n" + "    <thead>\n" + "    <tr>\n" + "        <th>Run Name</th>\n"
                            + "        <th>Platform</th>\n" + "        <th>Sequencer</th>\n");
            if (incAlias) {
                sb.append("        <th>Run Alias</th>\n");
            }
            if (incDescription) {
                sb.append("        <th>Run Description</th>\n");
            }
            sb.append("        <th>Pair End</th>\n" + "        <th>Status</th>\n" + "    </tr>\n"
                    + "    </thead>\n" + "    <tbody>");
            for (Reportable reportable : reportables) {
                Run run = (Run) reportable;
                sb.append("<tr><td>" + run.getName());
                sb.append("</td>");
                sb.append("<td> " + run.getPlatformType().getKey());
                sb.append("</td>");
                sb.append("<td> " + run.getSequencerReference().getName());
                sb.append("</td>");
                if (incAlias) {
                    sb.append("<td> " + run.getAlias());
                    sb.append("</td>");
                }
                if (incDescription) {
                    sb.append("<td> " + run.getDescription());
                    sb.append("</td>");
                }
                sb.append("<td> " + run.getPairedEnd().toString());
                sb.append("</td>");
                sb.append("<td> " + run.getStatus().getHealth().getKey());
                sb.append("</td></tr>");

                int statuscount = statusMap.containsKey(run.getStatus().getHealth().getKey())
                        ? statusMap.get(run.getStatus().getHealth().getKey())
                        : 0;
                statuscount++;
                statusMap.put(run.getStatus().getHealth().getKey(), statuscount);

                int platformcount = platformMap.containsKey(run.getPlatformType().getKey())
                        ? platformMap.get(run.getPlatformType().getKey())
                        : 0;
                platformcount++;
                platformMap.put(run.getPlatformType().getKey(), platformcount);
            }
            sb.append("    </tbody>\n" + "</table>");
            Integer unknown = statusMap.containsKey("Unknown") ? statusMap.get("Unknown") : 0;
            Integer completed = statusMap.containsKey("Completed") ? statusMap.get("Completed") : 0;
            Integer failed = statusMap.containsKey("Failed") ? statusMap.get("Failed") : 0;
            Integer started = statusMap.containsKey("Started") ? statusMap.get("Started") : 0;
            Integer stopped = statusMap.containsKey("Stopped") ? statusMap.get("Stopped") : 0;
            Integer running = statusMap.containsKey("Running") ? statusMap.get("Running") : 0;

            //jfreechart for status
            final DefaultPieDataset data = new DefaultPieDataset();
            data.setValue("Unknown " + unknown, unknown);
            data.setValue("Completed " + completed, completed);
            data.setValue("Failed " + failed, failed);
            data.setValue("Started " + started, started);
            data.setValue("Stopped " + stopped, stopped);
            data.setValue("Running " + running, running);

            final JFreeChart chart = ChartFactory.createPieChart("Run Status Information", // chart title
                    data, // data
                    false, // include legend
                    true, false);

            final PiePlot plot = (PiePlot) chart.getPlot();
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setBackgroundPaint(Color.white);
            plot.setForegroundAlpha(0.5f);
            plot.setNoDataMessage("No data to display");
            int r = generator.nextInt();
            File runchart = new File("../webapps/ROOT/styles/images/runsstatuschart" + r + ".png");
            try {
                ChartUtilities.saveChartAsPNG(runchart, chart, 500, 300);
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (chartbool) {
                sb.append("<br/><img src='/styles/images/runsstatuschart" + r + ".png'/>");
            }

            //        Integer illumina = platformMap.containsKey("Illumina") ? platformMap.get("Illumina") : 0;
            //        Integer ls454 = platformMap.containsKey("LS454") ? platformMap.get("LS454") : 0;
            //        Integer solid = platformMap.containsKey("Solid") ? platformMap.get("Solid") : 0;

            //jfreechart for platform
            //        final DefaultPieDataset platformdata = new DefaultPieDataset();
            //        platformdata.setValue("Illumina "+illumina, illumina);
            //        platformdata.setValue("LS454 "+ls454, ls454);
            //        platformdata.setValue("Solid "+solid, solid);
            //
            //        final JFreeChart platformchart = ChartFactory.createPieChart(
            //          "Run Platform Information",  // chart title
            //          platformdata,                   // data
            //          false,                   // include legend
            //          true,
            //          false
            //        );
            //
            //        final PiePlot platformplot = (PiePlot) platformchart.getPlot();
            //        platformplot.setStartAngle(290);
            //        platformplot.setDirection(Rotation.CLOCKWISE);
            //        platformplot.setBackgroundPaint(Color.white);
            //        platformplot.setForegroundAlpha(0.5f);
            //        platformplot.setNoDataMessage("No data to display");
            //        File runplatformchart = new File("../webapps/ROOT/styles/images/runsplatformchart" + r + ".png");
            //        try {
            //          ChartUtilities.saveChartAsPNG(runplatformchart, platformchart, 500, 300);
            //        }
            //        catch (IOException e) {
            //          e.printStackTrace();
            //        }
            //        if (chartbool) {
            //          sb.append(" <img src='/styles/images/runsplatformchart" + r + ".png'/>");
            //        }
        } else {
            sb.append("<h1>Run Information</h1><br/><div class='report'>Nothing to Report.");
        }

    }

    // footer
    sb.append("</div>\n" + "<div id=\"footer\">\n" + "    <br/>\n" + "\n"
            + "    <p>&copy; 2010 -2011 <a href=\"http://www.tgac.bbsrc.ac.uk/\" target=\"_blank\">The Genome Analysis Centre</a></p>\n"
            + "</div>\n" + "</body></html>");
    // end of footer
    return sb.toString();

}

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);//ww w .  j a v  a 2  s .c  om
    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:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java

public JFreeChart createDonorsReportsChart(PieDataset dataSet, String chartTitle) {

    JFreeChart chart = ChartFactory.createPieChart(chartTitle, dataSet, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(0);//from w  w w .  j a v  a  2 s.  c o  m
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java

@SuppressWarnings("unchecked")
@Override//from  w w  w.  j a  va  2 s.  co m
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class,
            DEFAULT_GRAPH_NO_DATA_MESSAGE);
    PieGraphData pieGraphData = makeDataSet();
    Map<Comparable, Paint> colors = pieGraphData.colors;

    this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false);

    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class,
            DEFAULT_BACKGROUND_COLOR);

    this.chart.setBackgroundPaint(backgroundColor);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setNoDataMessage(noDataMessage);

    if (!graphDisplayLabel) {
        plot.setLabelGenerator(null);
    } else {
        plot.setInteriorGap(0.001);
        plot.setMaximumLabelWidth(.3);
        //           plot.setIgnoreNullValues(true);
        plot.setIgnoreZeroValues(true);
        plot.setShadowPaint(null);
        //           plot.setOutlineVisible(false);
        //TODO use title font?
        Font font = plot.getLabelFont();
        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);
        plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f));
        plot.setLabelBackgroundPaint(labelColor);
        plot.setLabelShadowPaint(null);
        plot.setLabelOutlinePaint(null);
        plot.setLabelGap(0.001);
        plot.setLabelLinkMargin(0.0);
        plot.setLabelLinksVisible(true);
        //           plot.setSimpleLabels(true);
        //           plot.setCircular(true);
    }

    if (!graphBorder) {
        plot.setOutlineVisible(false);
    }

    if (title != null && !"".equals(title)) {
        TextTitle title1 = new TextTitle();
        title1.setText(title);
        title1.setFont(titleFont);
        title1.setPadding(3, 2, 5, 2);
        chart.setTitle(title1);
    } else {
        chart.setTitle((TextTitle) null);
    }
    plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1));
    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());

        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }

        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
        plot.setLegendLabelGenerator(new PieGraphLabelGenerator());
    }

    for (Comparable category : colors.keySet()) {
        plot.setSectionPaint(category, colors.get(category));
    }

    plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData));
    plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData));

    initialized = true;
}

From source file:utils.Graphs.java

public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    // add our data values
    int i = -1;/*  w w  w .j  a  v  a2  s . c  o m*/
    for (String title : titles) {
        i++;
        dataset.setValue(title, values[i]);
    }

    final JFreeChart chart =
            //                ChartFactory.createPieChart("", dataset, true, true, false);

            ChartFactory.createPieChart("", // chart title
                    dataset, // data
                    true, // include legend
                    true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    //PiePlot3D plot = (PiePlot3D) chart.getPlot();
    //plot.setStartAngle(290);
    plot.setStartAngle(45);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);

    //        final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(backgroundColor);

    //        plot.setLegendLabelGenerator(
    //        new StandardPieSectionLabelGenerator("{0} {2}"));

    chart.setBorderVisible(false);
    chart.getPlot().setOutlineVisible(false);
    chart.getLegend().setFrame(BlockBorder.NONE);

    // get the same background
    chart.setBackgroundPaint(backgroundColor);
    chart.getLegend().setBackgroundPaint(backgroundColor);

    // hide the shadow effects
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //chart.getLegend().setVisible(false);

    plot.setCircular(true);
    //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data found.");

    Color greenColor = new Color(0x8FBC0C);
    Color redColor = new Color(0xFF0000);
    //Color redColor = new Color(0xDA6022);

    plot.setSectionPaint(0, greenColor);
    plot.setSectionPaint(1, redColor);
    plot.setSectionOutlinesVisible(true);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(baseFolder, "chart.png");
    try {
        ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info);
    } catch (IOException ex) {
        Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        
    ////        final ChartPanel chartPanel = new ChartPanel(chart, true);
    //       final ChartPanel chartPanel = new ChartPanel(chart, true);
    //        chartPanel.setMinimumDrawWidth(0);
    //        chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    //        chartPanel.setMinimumDrawHeight(0);
    //        chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    //        JDialog dialog = new JDialog();
    //        dialog.add(chartPanel);
    //        dialog.setLayout(new GridLayout(1, 1));
    //        dialog.setSize(400, 200);
    //        dialog.setVisible(true);

    return file;
}

From source file:org.jfree.chart.demo.PieChartDemo4.java

/**
 * Default constructor./* ww w. ja  va  2 s  .co  m*/
 *
 * @param title  the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

    final Rotator rotator = new Rotator(plot);
    rotator.start();

}

From source file:velo.ejb.seam.action.HomeActionsBean.java

public void createChart() {
    ResourceList rl = new ResourceList();
    rl.getResource().setActive(true);/*ww w. j  a  v  a 2s  .  c  om*/
    rl.initialize();
    List<Resource> resources = rl.getResultList();

    //Retrieve a list of tasks from last day
    TaskList tl = new TaskList();
    List<Task> tasks = tl.getResultList();

    //build the summaries
    Map<String, Long> rTasks = new HashMap<String, Long>();

    for (Task currTask : tasks) {
        if (currTask instanceof ResourceTask) {
            ResourceTask rt = (ResourceTask) currTask;

            if (!rTasks.containsKey(rt.getResourceUniqueName())) {
                rTasks.put(rt.getResourceUniqueName(), new Long(0));
            }

            rTasks.put(rt.getResourceUniqueName(), rTasks.get(rt.getResourceUniqueName()) + 1);
        }
    }

    final DefaultPieDataset dataset = new DefaultPieDataset();
    for (Resource currResource : resources) {
        if (rTasks.containsKey(currResource.getUniqueName())) {
            dataset.setValue(currResource.getDisplayName() + "("
                    + rTasks.get(currResource.getUniqueName()).longValue() + ")",
                    rTasks.get(currResource.getUniqueName()));
        } else {
            dataset.setValue(currResource.getDisplayName() + "(0)", 0);
        }

    }

    final JFreeChart chart = ChartFactory.createPieChart("Tasks Amount (1 last day) per resource", // chart title
            dataset, // dataset
            true, // include legend
            true, false);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage("No data available");

    try {
        this.chart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(400, 400));
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:cn.edu.thss.iise.bpmdemo.charts.PieChartDemo4.java

/**
 * Default constructor.//from  w w w  . ja v  a 2 s  .  c o m
 *
 * @param title
 *            the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    // add table
    Object[][] data = { { "Kathy0", new Integer(0) }, { "Kathy1", new Integer(2) },
            { "Kathy2", new Integer(5) }, { "Kathy3", new Integer(5) }, { "Kathy4", new Integer(5) },
            { "Kathy5", new Integer(5) }, { "Kathy6", new Integer(5) }, { "Kathy7", new Integer(5) },
            { "Kathy8", new Integer(5) }, { "Kathy9", new Integer(5) } };
    String[] columnNames = { "Model Name", "Reuse Number" };
    JTable table = new JTable(data, columnNames);
    final JPanel panel = new JPanel();
    panel.add(chartPanel);
    panel.add(table);
    setContentPane(panel);
    final Rotator rotator = new Rotator(plot);
    rotator.start();

}

From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java

public JFreeChart createPatientReportsChart(PieDataset dataSet, String chartTitle) {
    //ChartFactory.createPieChart(chartTitle, dataSet, true, true, false);
    JFreeChart chart = ChartFactory.createPieChart(chartTitle, dataSet, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(0);/*from  w ww .j  a v a2s .c om*/
    plot.setDirection(Rotation.CLOCKWISE);
    //plot.setForegroundAlpha(0.8f);
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}