com.cete.dynamicpdf.pageelements.charting.axes
Class PercentageYAxisLabel



Example: The following example creates a date time 100 percent stacked area series chart and adds percentage yaxis labels to yaxis.

import com.cete.dynamicpdf.Document;
import com.cete.dynamicpdf.Page;
import com.cete.dynamicpdf.pageelements.charting.*;
import com.cete.dynamicpdf.pageelements.charting.axes.*;
import com.cete.dynamicpdf.pageelements.charting.series.*;
import java.util.Calendar;


 public class MyClass {

        public static void main(String args[]){
        // 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, 200);
        
        //Get the default plot area from the chart
        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);
        
        // Create yAxis and add labels to it
        PercentageYAxis yAxis = new PercentageYAxis();
        yAxis.getLabels().add(new PercentageYAxisLabel("0", 0));
        yAxis.getLabels().add(new PercentageYAxisLabel("20%", 20));
        yAxis.getLabels().add(new PercentageYAxisLabel("40%", 40));
        yAxis.getLabels().add(new PercentageYAxisLabel("60%", 60));
        yAxis.getLabels().add(new PercentageYAxisLabel("80%", 80));
        yAxis.getLabels().add(new PercentageYAxisLabel("100%", 100));
        
        // Create a date time xAxis
        DateTimeXAxis xAxis = new DateTimeXAxis();
        
        // Create positions
        Calendar p0=Calendar.getInstance();
        p0.set(2007,0,1);
        Calendar p1=Calendar.getInstance();
        p1.set(2007,1,1);
        Calendar p2=Calendar.getInstance();
        p2.set(2007,2,1);
        Calendar p3=Calendar.getInstance();
        p3.set(2007,3,1);
        
        // Create a date time 100percent stacked area series and add values to it
        DateTime100PercentStackedAreaSeriesElement areaSeriesElement1 = new DateTime100PercentStackedAreaSeriesElement("Website A");
        areaSeriesElement1.getValues().add(5, p0);
        areaSeriesElement1.getValues().add(7, p1);
        areaSeriesElement1.getValues().add(9, p2);
        areaSeriesElement1.getValues().add(6, p3);
        DateTime100PercentStackedAreaSeriesElement areaSeriesElement2 = new DateTime100PercentStackedAreaSeriesElement("Website B");
        areaSeriesElement2.getValues().add(4, p0);
        areaSeriesElement2.getValues().add(2, p1);
        areaSeriesElement2.getValues().add(5, p2);
        areaSeriesElement2.getValues().add(8, p3);
        DateTime100PercentStackedAreaSeriesElement areaSeriesElement3 = new DateTime100PercentStackedAreaSeriesElement("Website C");
        areaSeriesElement3.getValues().add(2, p0);
        areaSeriesElement3.getValues().add(4, p1);
        areaSeriesElement3.getValues().add(6, p2);
        areaSeriesElement3.getValues().add(9, p3);
        
        // Create a date time 100percent  stacked area series and add date time 100percent  stacked area series elements to it
        DateTime100PercentStackedAreaSeries stackedAreaSeries1 = new DateTime100PercentStackedAreaSeries(xAxis, yAxis);
        stackedAreaSeries1.add(areaSeriesElement1);
        stackedAreaSeries1.add(areaSeriesElement2);
        stackedAreaSeries1.add(areaSeriesElement3);
        
        // add date time 100percent  stacked area series to the plot area
        plotArea.getSeries().add(stackedAreaSeries1);
        
        // Set label list format for the axislabels
        stackedAreaSeries1.getXAxis().setLabelFormat("MMM");
        
        // add the chart to the page
        page.getElements().add(chart);

        // Save the PDF
        document.draw("[Physicalpath]/MyDocument.pdf");
       }
 }