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:org.codehaus.mojo.dashboard.report.plugin.chart.PieChartRenderer.java

public void createChart() {

    PieDataset dataset = (PieDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createPieChart(this.datasetStrategy.getTitle(), dataset, true, true, false);
    PiePlot plot = (PiePlot) report.getPlot();
    //        plot.setCircular( false );
    plot.setDirection(Rotation.ANTICLOCKWISE);
    /*//from   w ww. ja v a2  s  .  c o  m
     * plot.setExplodePercent(0, 0.15D); plot.setExplodePercent(1, 0.15D);
     */
    //        plot.setInteriorGap( PieChartRenderer.INTERIOR_GAP );
    plot.setLabelFont(new Font("Lucida", 0, PieChartRenderer.FONT_SIZE));
    plot.setLabelGap(PieChartRenderer.LABEL_GAP);
    plot.setNoDataMessage("No data available");
    plot.setStartAngle(PieChartRenderer.START_ANGLE);
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < dataset.getItemCount() && i < paints.length; i++) {
        plot.setSectionPaint(dataset.getKey(i), paints[i]);
    }
}

From source file:name.martingeisse.reporting.definition.keycount.UnboundChartBlock.java

@Override
public ChartBlock bindToData(final DataSources dataSources) {

    // generate the dataset from the query
    DefaultPieDataset dataset = new DefaultPieDataset();
    IKeyCountResultSet resultSet = query.bindToData(dataSources);
    while (resultSet.next()) {
        KeyCountEntry entry = resultSet.get();
        dataset.setValue(entry.getKey(), entry.getCount());
    }//from w  ww.  j  a  v  a  2 s  .co m
    resultSet.close();

    // generate the chart
    JFreeChart chart = ChartFactory.createPieChart("My Title", dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.8f);
    return new ChartBlock(chart);

}

From source file:org.posterita.core.PieChart.java

public JFreeChart createChart() throws OperationException {
    if (dataset == null) {
        throw new OperationException("Cannot create Pie chart: cause -> dataset empty!");
    }/*from  w  w  w .j a  v a  2 s  .c  o  m*/

    switch (type) {
    case PIE_FLAT:
        chart = ChartFactory.createPieChart(title, dataset, showLegend, showTooltip, true);
        break;

    case PIE_3D:
        chart = ChartFactory.createPieChart3D(title, dataset, showLegend, showTooltip, true);
        break;

    default:
        throw new OperationException("Invalid Piechart type! Can only be Piechart.PIE_FLAT or Piechart.PIE_3D");
    }

    //setting subtitle
    if (subtitle != null) {
        TextTitle title = new TextTitle(subtitle);
        chart.addSubtitle(title);
    }

    return chart;

}

From source file:com.orsonpdf.demo.PDFPieChartDemo1.java

/**
 * Creates a chart.//  w  w  w  .j  av  a 2 s.c  o  m
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", dataset, false, false,
            false);

    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

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

    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);
    plot.setShadowPaint(null);
    plot.setLabelShadowPaint(null);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 1.0f);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

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

public GraphicalInventoryPieChart(int curriculumId) {
    this.curriculumId = curriculumId;
    setModal(true);//from  w  ww .  j  a  v  a2  s  .c o m

    int percentage = 0;
    VerticalLayout v = new VerticalLayout();
    DefaultPieDataset dataset = new DefaultPieDataset();

    for (BloomsClass b : BloomsClass.values()) {
        percentage = (int) calculatePercentageOfItemsPerBloomsClass(
                rs.getTotalItemsBySubject(getCurriculumId()),
                rs.getTotalItemsByBloomsCass(getCurriculumId(), tq.getBloomsClassId(b.toString())));

        dataset.setValue(b + " " + percentage + "%", percentage);
    }

    JFreeChart chart = ChartFactory.createPieChart(
            "Inventory of Items for " + cs.getCurriculumById(getCurriculumId()).getSubject(), dataset, true,
            true, false);

    //        JFreeChartWrapper wrapper = new JFreeChartWrapper(chart){
    //            
    //            @Override
    //            public void attach(){
    //                super.attach();
    //                setResource("src", getSource());
    //            }
    //            
    //        };

    v.addComponent(new ReportChartWrapper(chart, null, null));
    v.setWidthUndefined();
    v.setHeightUndefined();

    setContent(v);
    getContent().setWidthUndefined();
    getContent().setHeightUndefined();
    center();
}

From source file:playground.yu.utils.charts.PieChart.java

private JFreeChart createChart(String title, DefaultPieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            true, // include legend
            true, false);//from  w ww .  j  a  va2s. c  o m
    return chart;
}

From source file:org.primefaces.examples.view.DynamicImageController.java

public DynamicImageController() {
    try {/*w w  w  .  j a  va  2s.c  om*/
        //Graphic Text
        BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bufferedImg.createGraphics();
        g2.drawString("This is a text", 0, 10);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(bufferedImg, "png", os);
        graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");

        //Chart
        JFreeChart jfreechart = ChartFactory.createPieChart("Turkish Cities", createDataset(), true, true,
                false);
        File chartFile = new File("dynamichart");
        ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300);
        chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");

        //Barcode
        File barcodeFile = new File("dynamicbarcode");
        BarcodeImageHandler.saveJPEG(BarcodeFactory.createCode128("PRIMEFACES"), barcodeFile);
        barcode = new DefaultStreamedContent(new FileInputStream(barcodeFile), "image/jpeg");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.datamyne.charts.AlmostThereDemo.java

/**
 * Gets a {@link JFreeChart}.// w  ww  .j a  v a 2  s  .  c o  m
 * @return {@link JFreeChart}.
 */
public JFreeChart getChart() {
    //create dummy data
    //taken from http://www.java2s.com/Code/Java/Chart/JFreeChartPieChartDemo1.htm
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(43.2));
    dataset.setValue("Two", new Double(10.0));
    dataset.setValue("Three", new Double(27.5));
    dataset.setValue("Four", new Double(17.5));
    dataset.setValue("Five", new Double(11.0));
    dataset.setValue("Six", new Double(19.4));

    //use the ChartFactory to create a pie chart
    JFreeChart chart = ChartFactory.createPieChart("Dummy Data", dataset, true, true, false);
    return chart;
}

From source file:Software_Jframes.chart.java

public void piechart(JDesktopPane jDesktopPane1, String pid) {

    DefaultPieDataset piedataset = new DefaultPieDataset();
    try {/*www  .j a v a2  s. c  o  m*/
        ResultSet rs = db.statement()
                .executeQuery("select name,cost from project_level_payment where projectid='" + pid + "' ");
        while (rs.next()) {
            String cost = rs.getString("cost");
            int cost_int1 = Integer.parseInt(cost);

            String name = rs.getString("name");

            piedataset.setValue(name, new Integer(cost_int1));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    JFreeChart chart = ChartFactory.createPieChart("Costs for Project", piedataset, true, true, true);
    PiePlot p = (PiePlot) chart.getPlot();
    p.setBackgroundPaint(Color.white);
    ChartPanel panel = new ChartPanel(chart);
    jDesktopPane1.add(panel).setSize(440, 300);
}

From source file:com.anevis.jfreechartsamplespring.chart.ChartServiceImpl.java

private JFreeChart createPieChart() {
    List<PieChartData> dataList = pieChartDataRepository.findAll();
    DefaultPieDataset dataSet = new DefaultPieDataset();

    dataList.forEach(data -> dataSet.setValue(data.getCountry(), data.getWeight()));

    JFreeChart chart = ChartFactory.createPieChart("Anteil am Fondsvermgen", dataSet, true, false,
            Locale.GERMANY);//  w  w  w.j  a  v  a  2 s.c  om

    return chart;
}