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

    Polygons are used to display information in Area Charts. There are three different types:

    Normal

    Normal Area charts create polygons based on the data. They use DateTimeXAxis or IndexedXAxis as the XAxis based on the series and NumericYAxis as the YAxis.
                                          Figure 1 - Normal Area Chart
    [Java]
       // Create a PDF Document
       Document document = new Document();
       // Create a Page and add it to the document
       Page page = new Page();
       document.getPages().add(page);
            
       // Create a chart
       Chart chart = new Chart(0, 0, 400, 230);
       // Create a plot area
       PlotArea plotArea = chart.getPrimaryPlotArea();
            
       // Create header titles and add it to the chart
       Title title1 = new Title("Website Visitors");
       Title title2 = new Title("Year - 2007");
       chart.getHeaderTitles().add(title1);
       chart.getHeaderTitles().add(title2);
       
       AutoGradient myAutogradient1 = new AutoGradient(90.0f, CmykColor.getRed(), CmykColor.getIndianRed())     
       // Create indexed area series and add values to it
       
       IndexedAreaSeries areaSeries1 = new IndexedAreaSeries("Website A", , , myAutogradient1);
       areaSeries1.getValues().add(new float[]{5, 7, 9, 6});
           
       // Add indexed area series to the plot area
       plotArea.getSeries().add(areaSeries1);
            
       // Create a title and add it to the YAxis
       Title lTitle = new Title("Visitors (in millions)");
       areaSeries1.getYAxis().getTitles().add(lTitle);
            
       //Adding AxisLabels to the XAxis
       areaSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q1", 0));
       areaSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q2", 1));
       areaSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q3", 2));
       areaSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q4", 3));
            
       // Add the chart to the page
       page.getElements().add(chart);
       // Save the PDF
       document.draw("[PhysicalPath]/MyDocument.pdf");
    
    Stacked
    Stacked charts display related data, one on top of the other. They use DateTimeXAxis or IndexedXAxis as the XAxis based on the series and NumericYAxis as the YAxis.
                                    Figure 2 - Stacked Area Chart
    [Java]
       // Create a PDF Document
       Document document = new Document();
       // Create a Page and add it to the document
       Page page = new Page();
       document.getPages().add(page);
            
       // Create a chart
       Chart chart = new Chart(0, 0, 400, 230);
       // Create a plot area
       PlotArea plotArea = chart.getPrimaryPlotArea();
            
       // Create header titles and add it to the chart
       Title title1 = new Title("Website Visitors");
       Title title2 = new Title("Year - 2007");
       chart.getHeaderTitles().add(title1);
       chart.getHeaderTitles().add(title2);
    
       AutoGradient myAutogradient1 = new AutoGradient(90.0f, CmykColor.getRed(), CmykColor.getIndianRed()) 
    AutoGradient myAutogradient2 = new AutoGradient(90.0f, CmykColor.getGreen(), CmykColor.getYellowGreen())
    AutoGradient myAutogradient3 = new AutoGradient(120.0f, CmykColor.getBlue(), CmykColor.getLightBlue()) // Create indexed stacked area series elements and add values to it IndexedStackedAreaSeriesElement seriesElement1 = new IndexedStackedAreaSeriesElement("Website A", myAutogradient1); seriesElement1.getValues().add(new float[] { 5, 7, 9, 6 }); IndexedStackedAreaSeriesElement seriesElement2 = new IndexedStackedAreaSeriesElement("Website B", myAutogradient2); seriesElement2.getValues().add(new float[] { 4, 2, 5, 8 }); IndexedStackedAreaSeriesElement seriesElement3 = new IndexedStackedAreaSeriesElement("Website C", myAutogradient3); seriesElement3.getValues().add(new float[] { 2, 4, 6, 9 }); // Create a Indexed Stacked Area Series IndexedStackedAreaSeries areaSeries = new IndexedStackedAreaSeries(); // Add indexed stacked area series elements to the Indexed Stacked Area Series areaSeries.add(seriesElement1); areaSeries.add(seriesElement2); areaSeries.add(seriesElement3); // Add series to the plot area plotArea.getSeries().add(areaSeries); // Create a title and add it to the YAxis Title lTitle = new Title("Visitors (in millions)"); areaSeries.getYAxis().getTitles().add(lTitle); //Adding AxisLabels to the XAxis areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q1", 0)); areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q2", 1)); areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q3", 2)); areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q4", 3)); // Add the chart to the page page.getElements().add(chart); // Save the PDF document.draw("[PhysicalPath]/MyDocument.pdf");
    100% Stacked
    100% stacked charts are similar to stacked charts, but here the data is expressed as a percentage. They use DateTimeXAxis or IndexedXAxis as the XAxis based on the series and PercentageYAxis as the YAxis.
                                Figure 3 - Stacked 100% Area Chart
    [Java]
       // Create a PDF Document
       Document document = new Document();
       // Create a Page and add it to the document
       Page page = new Page();
       document.getPages().add(page);
            
       // Create a chart
       Chart chart = new Chart(0, 0, 400, 230);
       // Create a plot area
       PlotArea plotArea = chart.getPrimaryPlotArea();
            
       // Create header titles and add it to the chart
       Title title1 = new Title("Website Visitors");
       Title title2 = new Title("Year - 2007");
       chart.getHeaderTitles().add(title1);
       chart.getHeaderTitles().add(title2);
    
       AutoGradient myAutogradient1 = new AutoGradient(90.0, CmykColor.getRed(), CmykColor.getIndianRed()) 
    AutoGradient myAutogradient2 = new AutoGradient(90.0F, CmykColor.getGreen(), CmykColor.getYellowGreen())
    AutoGradient myAutogradient3 = new AutoGradient(120.0F, CmykColor.getBlue(), CmykColor.getLightBlue()) // Create a indexed 100% stacked area series elements and add values to it Indexed100PercentStackedAreaSeriesElement seriesElement1 = new Indexed100PercentStackedAreaSeriesElement("Website A", myAutogradient1); seriesElement1.getValues().add(new float[] { 5, 7, 9, 6 }); Indexed100PercentStackedAreaSeriesElement seriesElement2 = new Indexed100PercentStackedAreaSeriesElement("Website B", myAutogradient2); seriesElement2.getValues().add(new float[] { 4, 2, 5, 8 }); Indexed100PercentStackedAreaSeriesElement seriesElement3 = new Indexed100PercentStackedAreaSeriesElement("Website C", myAutogradient3); seriesElement3.getValues().add(new float[] { 2, 4, 6, 9 }); // Create a Indexed 100% Stacked Area Series Indexed100PercentStackedAreaSeries areaSeries = new Indexed100PercentStackedAreaSeries(); // Add indexed 100% stacked area series elements to the Indexed 100% Stacked Area Series areaSeries.add(seriesElement1); areaSeries.add(seriesElement2); areaSeries.add(seriesElement3); // Add series to the plot area plotArea.getSeries().add(areaSeries); // Create a title and add it to the yAxis Title lTitle = new Title("Visitors (in millions)"); areaSeries.getYAxis().getTitles().add(lTitle); //Adding AxisLabels to the XAxis areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q1", 0)); areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q2", 1)); areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q3", 2)); areaSeries.getXAxis().getLabels().add(new IndexedXAxisLabel("Q4", 3)); // Add the chart to the page page.getElements().add(chart); // Save the PDF document.draw("[PhysicalPath]/MyDocument.pdf");
    See Also