Example usage for org.jfree.chart ChartFactory createPieChart

List of usage examples for org.jfree.chart ChartFactory createPieChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createPieChart.

Prototype

public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips,
        boolean urls) 

Source Link

Document

Creates a pie chart with default settings.

Usage

From source file:ispd.gui.auxiliar.Graficos.java

public void criarProcessamento(Map<String, MetricasProcessamento> mProcess) {
    DefaultCategoryDataset dadosGraficoProcessamento = new DefaultCategoryDataset();
    DefaultPieDataset dadosGraficoPizzaProcessamento = new DefaultPieDataset();

    if (mProcess != null) {
        for (Map.Entry<String, MetricasProcessamento> entry : mProcess.entrySet()) {
            MetricasProcessamento mt = entry.getValue();
            if (mt.getnumeroMaquina() == 0) {
                dadosGraficoProcessamento.addValue(mt.getMFlopsProcessados(), "vermelho", mt.getId());
                dadosGraficoPizzaProcessamento.insertValue(0, mt.getId(), mt.getMFlopsProcessados());
            } else {
                dadosGraficoProcessamento.addValue(mt.getMFlopsProcessados(), "vermelho",
                        mt.getId() + " node " + mt.getnumeroMaquina());
                dadosGraficoPizzaProcessamento.insertValue(0, mt.getId() + " node " + mt.getnumeroMaquina(),
                        mt.getMFlopsProcessados());
            }//from   w  ww .j a  v a2s  .c  o m
        }
    }

    JFreeChart jfc = ChartFactory.createBarChart("Total processed on each resource", //Titulo
            "Resource", // Eixo X
            "Units", //Eixo Y
            dadosGraficoProcessamento, // Dados para o grafico
            PlotOrientation.VERTICAL, //Orientacao do grafico
            false, false, false); // exibir: legendas, tooltips, url
    //Inclina nome da barra em 45 graus
    if (mProcess != null && mProcess.size() > 10) {
        jfc.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    }
    ProcessingBarChart = new ChartPanel(jfc);
    ProcessingBarChart.setPreferredSize(new Dimension(600, 300));

    jfc = ChartFactory.createPieChart("Total processed on each resource", //Titulo
            dadosGraficoPizzaProcessamento, // Dados para o grafico
            true, false, false);
    ProcessingPieChart = new ChartPanel(jfc);
    ProcessingPieChart.setPreferredSize(new Dimension(600, 300));

}

From source file:com.etest.view.tq.charts.ItemAnalysisGraphicalViewAll.java

JFreeChartWrapper getDifficultIndexChart() {
    DefaultPieDataset difficultyDataSet = new DefaultPieDataset();
    for (String s : difficulty) {
        switch (s) {
        case "Very Difficult": {
            percentage = (int) calculatePercentageOfAnalyzedItems(
                    rs.getTotalAnalyzedItemsBySubject(getCurriculumId()),
                    rs.getTotalItemByDifficultyIndex(getCurriculumId(), 0, 0.19));
            difficultyDataSet.setValue(s + " " + percentage + "%", percentage);
            break;
        }//from  ww w  .  j  a v  a 2s .  co m
        case "Difficult": {
            percentage = (int) calculatePercentageOfAnalyzedItems(
                    rs.getTotalAnalyzedItemsBySubject(getCurriculumId()),
                    rs.getTotalItemByDifficultyIndex(getCurriculumId(), 0.20, 0.39));
            difficultyDataSet.setValue(s + " " + percentage + "%", percentage);
            break;
        }
        case "Average": {
            percentage = (int) calculatePercentageOfAnalyzedItems(
                    rs.getTotalAnalyzedItemsBySubject(getCurriculumId()),
                    rs.getTotalItemByDifficultyIndex(getCurriculumId(), 0.40, 0.60));
            difficultyDataSet.setValue(s + " " + percentage + "%", percentage);
            break;
        }
        case "Easy": {
            percentage = (int) calculatePercentageOfAnalyzedItems(
                    rs.getTotalAnalyzedItemsBySubject(getCurriculumId()),
                    rs.getTotalItemByDifficultyIndex(getCurriculumId(), 0.61, 0.80));
            difficultyDataSet.setValue(s + " " + percentage + "%", percentage);
            break;
        }
        default: {
            percentage = (int) calculatePercentageOfAnalyzedItems(
                    rs.getTotalAnalyzedItemsBySubject(getCurriculumId()),
                    rs.getTotalItemByDifficultyIndex(getCurriculumId(), 0.81, 1));
            difficultyDataSet.setValue(s + " " + percentage + "%", percentage);
            break;
        }
        }

    }

    JFreeChart difficultIndexChart = ChartFactory.createPieChart("Difficulty Index", difficultyDataSet, true,
            true, false);

    return new ReportChartWrapper(difficultIndexChart, "550px", "550px");
}

From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreatePieChartView.java

private JFreeChart createCounselingTypePieChartView() {
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    VCTModuleService service = Context.getService(VCTModuleService.class);

    try {/*  w  w w.jav  a 2  s  .c  o m*/
        Date reportingDate = new Date();
        int numberOfIndividual = service.getVCTClientsBasedOnCounselingType(1, reportingDate).size();
        int numberOfCouples = service.getVCTClientsBasedOnCounselingType(2, reportingDate).size();
        int numberOfNotCounseled = service.getVCTClientsBasedOnCounselingType(3, reportingDate).size();

        int all = numberOfIndividual + numberOfCouples + numberOfNotCounseled;

        Float percentageIndividual = new Float(100 * numberOfIndividual / all);
        pieDataset.setValue("Individual (" + numberOfIndividual + " , " + percentageIndividual + "%)",
                percentageIndividual);

        Float percentageCouple = new Float(100 * numberOfCouples / all);
        pieDataset.setValue("Couples (" + numberOfCouples + " , " + percentageCouple + "%)", percentageCouple);

        Float percentageNotCounseled = new Float(100 * numberOfNotCounseled / all);
        pieDataset.setValue("Not Counseled (" + numberOfNotCounseled + " , " + percentageNotCounseled + "%)",
                percentageNotCounseled);

        JFreeChart chart = ChartFactory.createPieChart(
                VCTTracUtil.getMessage("vcttrac.statistic.graph.typeofcounseling", null), pieDataset, true,
                true, false);

        return chart;
    } catch (Exception e) {
        log.error(">>COUNSELING>>TYPE>>PIE>>CHART>> " + e.getMessage());
        e.printStackTrace();
        return ChartFactory.createPieChart(
                VCTTracUtil.getMessage("vcttrac.statistic.graph.typeofcounseling", null), null, true, true,
                false);
    }
}

From source file:ca.sqlpower.architect.swingui.ProfileGraphPanel.java

public ProfileGraphPanel(ProfilePanel panel, int rowCount) {
    this.profilePanel = panel;
    this.rowCount = rowCount;

    FormLayout displayLayout = new FormLayout("4dlu, default, 4dlu, 100dlu, 4dlu, fill:default:grow, 4dlu", // columns
            "4dlu, default, 6dlu"); // rows
    CellConstraints cc = new CellConstraints();

    validResultsPanel = ProfileGraphPanel.logger.isDebugEnabled() ? new FormDebugPanel(displayLayout)
            : new JPanel(displayLayout);
    validResultsPanel.setBorder(BorderFactory.createEtchedBorder());

    Font bodyFont = validResultsPanel.getFont();
    Font titleFont = bodyFont.deriveFont(Font.BOLD, bodyFont.getSize() * 1.25F);

    title = new JLabel("Column Name");
    title.setFont(titleFont);/*  w ww  .j  a  va 2 s  . c  o m*/

    PanelBuilder pb = new PanelBuilder(displayLayout, validResultsPanel);
    pb.add(title, cc.xyw(2, 2, 5));

    int row = 4;
    rowCountDisplay = makeInfoRow(pb, "RowCount", row);
    row += 2;
    nullableLabel = makeInfoRow(pb, "Nullable", row);
    row += 2;
    nullCountLabel = makeInfoRow(pb, "Null Count", row);
    row += 2;
    nullPercentLabel = makeInfoRow(pb, "% Null Records", row);
    row += 2;
    minLengthLabel = makeInfoRow(pb, "Minimum Length", row);
    row += 2;
    maxLengthLabel = makeInfoRow(pb, "Maximum Length", row);
    row += 2;
    uniqueCountLabel = makeInfoRow(pb, "Unique Values", row);
    row += 2;
    uniquePercentLabel = makeInfoRow(pb, "% Unique", row);
    row += 2;
    minValue = makeInfoRow(pb, "Minimum Value", row);
    row += 2;
    maxValue = makeInfoRow(pb, "Maximum Value", row);
    row += 2;
    avgValue = makeInfoRow(pb, "Average Value", row);
    row += 2;

    freqValueTable = new FreqValueTable(null);
    freqValueSp = new JScrollPane(freqValueTable);

    pb.appendRow("fill:10dlu:grow");
    pb.appendRow("fill:default:grow");
    pb.add(freqValueSp, cc.xyw(2, row + 1, 3));

    // Now add something to represent the chart
    JFreeChart createPieChart = ChartFactory.createPieChart("", new DefaultPieDataset(new DefaultKeyedValues()),
            false, false, false);
    chartPanel = new ChartPanel(createPieChart);
    chartPanel.setPreferredSize(new Dimension(300, 300));

    if (panel.getProfileManager().getWorkspaceContainer() instanceof ArchitectSession
            && ((ArchitectSession) panel.getProfileManager().getWorkspaceContainer()).isEnterpriseSession()) {
        pb.add(new JLabel("Column Profile Notes"), cc.xy(6, 2));
        notesField = new JTextArea();
        notesField.setLineWrap(true);
        notesField.setWrapStyleWord(true);
        JScrollPane notesScroll = new JScrollPane(notesField);
        notesScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        notesScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        pb.add(notesScroll, cc.xywh(6, 4, 1, row - 4));

        pb.appendRow("fill:4dlu:grow");
        pb.appendRow("4dlu");

        pb.add(chartPanel, cc.xy(6, row + 1));
    } else {
        pb.appendRow("fill:4dlu:grow");
        pb.appendRow("4dlu");
        pb.add(chartPanel, cc.xywh(6, 4, 1, row - 2));
    }

    invalidResultsPanel = new JPanel(new BorderLayout());
    invalidResultsLabel = new JLabel("No error message yet");
    invalidResultsPanel.add(invalidResultsLabel);

    displayArea = new JPanel(new GridLayout(1, 1));
    displayArea.setPreferredSize(validResultsPanel.getPreferredSize());
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.piecharts.LinkablePie.java

public JFreeChart createChart(DatasetMap datasets) {
    Dataset dataset = (Dataset) datasets.getDatasets().get("1");

    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;/* w  w w .j  ava2s  . c o  m*/

    JFreeChart chart = null;

    if (!threeD) {
        chart = ChartFactory.createPieChart(name, (PieDataset) dataset, // data
                legend, // include legend
                true, false);

        chart.setBackgroundPaint(color);

        TextTitle title = chart.getTitle();
        title.setToolTipText("A title tooltip!");

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setNoDataMessage("No data available");

        if (percentage == false) {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
        } else {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        }

        MyPieUrlGenerator pieUrl = new MyPieUrlGenerator(rootUrl);
        pieUrl.setDocument_composition(document_composition);
        pieUrl.setCategoryUrlLabel(categoryUrlName);
        pieUrl.setDrillDocTitle(drillDocTitle);
        pieUrl.setTarget(target);

        plot.setURLGenerator(pieUrl);

    } else {
        chart = ChartFactory.createPieChart3D(name, (PieDataset) dataset, // data
                true, // include legend
                true, false);

        chart.setBackgroundPaint(color);

        TextTitle title = chart.getTitle();
        title.setToolTipText("A title tooltip!");

        PiePlot3D plot = (PiePlot3D) chart.getPlot();

        plot.setDarkerSides(true);
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(1.0f);
        plot.setDepthFactor(0.2);

        plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setNoDataMessage("No data available");

        //org.jfree.chart.renderer.category.BarRenderer renderer = new org.jfree.chart.renderer.category.AreaRenderer);

        MyPieUrlGenerator pieUrl = new MyPieUrlGenerator(rootUrl);
        pieUrl.setDocument_composition(document_composition);
        pieUrl.setCategoryUrlLabel(categoryUrlName);
        pieUrl.setDrillDocTitle(drillDocTitle);
        pieUrl.setTarget(target);

        plot.setURLGenerator(pieUrl);

        if (percentage == false) {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
        } else {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        }
    }

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    return chart;

}

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

private ChartPanel buildPiePanel() {
    JFreeChart chart = ChartFactory.createPieChart(null, m_pieDataset, true, false, false);

    setupPiePlot((PiePlot) chart.getPlot());
    setupPieLegend(chart);/*from   w  w  w  . j av a 2 s.  c o m*/

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDisplayToolTips(false);

    /*
     * RED_FLAG this is a WORKAROUND TO a JFreeChart bug (as of 1.0.4) which
     * causes an affine transform to be applied to charts smaller than
     * 300x200. If the minimum sizes are not set to the same value, the
     * chart and legend are scaled by the proprtion! see
     * http://www.jfree.org/phpBB2/viewtopic.php?t=16972
     */
    chartPanel.setMinimumDrawHeight(300);
    chartPanel.setMinimumDrawWidth(300);

    return chartPanel;
}

From source file:aplicarFiltros.PanelResultado.java

public void graficar() {

    //Grafico de cantidad de Pixeles
    JFreeChart chartPixel = ChartFactory.createPieChart("Clasificacin", datasetPixel, true, true, false);
    chartPixel.setBackgroundPaint(Color.ORANGE);
    PiePlot plotPixel = (PiePlot) chartPixel.getPlot();
    //Color de las etiquetas
    plotPixel.setLabelBackgroundPaint(Color.ORANGE);
    //Color de el fondo del grfico
    plotPixel.setBackgroundPaint(Color.WHITE);
    plotPixel.setNoDataMessage("No hay data");

    ChartPanel panelPixel = new ChartPanel(chartPixel);
    final JPanel contentPixel = new JPanel(new BorderLayout());
    contentPixel.add(panelPixel);//from   ww w.  ja  va2s  . c om
    //panelPixel.setPreferredSize(new java.awt.Dimension(500, 250));
    panelGraficoPixel.setPreferredSize(new java.awt.Dimension(500, 180));

    this.panelGraficoPixel.setLayout(new BorderLayout());
    this.panelGraficoPixel.add(contentPixel);
    contentPixel.setVisible(true);
    this.panelGraficoPixel.setVisible(true);
}

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  a  2 s. c  o m*/
    plot.setDirection(Rotation.CLOCKWISE);
    //plot.setForegroundAlpha(0.8f);
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo4.java

protected JFreeChart createChart(PieDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title
            dataset, // dataset
            !legendPanelOn, // include legend
            true, false);/*  w w  w.j  a va 2s . c om*/

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    for (int i = 0; i < pulloutFlag.length; i++) {
        //System.out.println("\""+pulloutFlag[i]+"\"");
        if (isPullout(i)) {
            Comparable key = dataset.getKey(i);
            plot.setExplodePercent(key, 0.30);
        }
    }
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }
    setCategorySummary(dataset);
    return chart;
}

From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java

/**
 * Creates a sample pie chart./* w w  w.j  av a  2  s .co m*/
 *
 * @return a pie chart.
 */
private JFreeChart createPieChart() {

    // create a dataset...
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("One", new Double(43.2));
    data.setValue("Two", new Double(10.0));
    data.setValue("Three", new Double(27.5));
    data.setValue("Four", new Double(17.5));
    data.setValue("Five", new Double(11.0));
    data.setValue("Six", new Double(19.4));

    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", data, true, true, false);
    return chart;

}