ceTe Software Help Library for Java August - 2020
DynamicPDF Generator for Java / Programming with Generator for Java / Charts / Chart Types / Pie Chart
In This Topic
    Pie Chart
    In This Topic

    Pie Charts use a circle to display the information. The circle is divided into different parts depending on the data. Each part will display the related piece of information.

                              Figure 1 - An example Pie Chart

    [Java]
        // Create a PDF Document
        Document document = new Document();
        // Create a Page and add it to the document
        Page page = new Page(PageSize.A4, PageOrientation.LANDSCAPE);
        document.getPages().add(page);
            
        // Create a chart
        Chart chart = new Chart(0, 0, 700, 400);
        // Add a plot area to the chart
        PlotArea plotArea = chart.getPlotAreas().add(50, 50, 300, 300);
            
        // Create the Header titles and add it to the chart
        Title tTitle = new Title("Website Viewers (in millions)");
        Title tTitle1 = new Title("Year 2007");
        chart.getHeaderTitles().add(tTitle);
        chart.getHeaderTitles().add(tTitle1);
            
        // Create a scalar datalabel
        ScalarDataLabel da = new ScalarDataLabel(true, false, false);
        // Create a pie series
        PieSeries pieSeries = new PieSeries();
        // Set scalar datalabel to the pie series
        pieSeries.setDataLabel(da);
        // Add series to the plot area
        plotArea.getSeries().add(pieSeries);
         
    AutoGradient myAutogradient1 = new AutoGradient(90.0f, CmykColor.getRed(), CmykColor.getIndianRed())
    AutoGradient myAutogradient2 = new AutoGradient(90.0f, CmykColor.getGreen(), CmykColor.getYellowGreen())
    AutoGradient myAutogradient3 = new AutoGradient(90.0f, CmykColor.getBlue(), CmykColor.getLightBlue()) //Add pie series elements to the pie series pieSeries.getElements().add(27, "Website A", myAutogradient1); pieSeries.getElements().add(19, "Website B", myAutogradient2); pieSeries.getElements().add(21, "Website C", myAutogradient3); // Add the chart to the page page.getElements().add(chart); // Save the pdf document.draw("[PhysicalPath]/MyDocument.pdf");
    See Also