Example: The following example creates indexed 100 percent stacked column series elements and creates indexed 100 percent stacked column series chart to it.
import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.charting.*;
import com.cete.dynamicpdf.pageelements.charting.series.*;
import com.cete.dynamicpdf.pageelements.charting.axes.*;
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 a indexed xAxis
IndexedXAxis xAxis = new IndexedXAxis();
// Create a percentage yAxis
PercentageYAxis yAxis = new PercentageYAxis();
// Create a indexed 100 percent stacked column series element and add values to it
Indexed100PercentStackedColumnSeriesElement seriesElement1 = new Indexed100PercentStackedColumnSeriesElement("Website A");
seriesElement1.getValues().add(new float[] { 5, 7, 9, 6 });
Indexed100PercentStackedColumnSeriesElement seriesElement2 = new Indexed100PercentStackedColumnSeriesElement("Website B");
seriesElement2.getValues().add(new float[] { 4, 2, 5, 8 });
Indexed100PercentStackedColumnSeriesElement seriesElement3 = new Indexed100PercentStackedColumnSeriesElement("Website C");
seriesElement3.getValues().add(new float[] { 2, 4, 6, 9 });
// Create a indexed 100 percent stacked column series and add indexed 100 percent stacked column series elements to it
Indexed100PercentStackedColumnSeries stackedColumnSeries1 = new Indexed100PercentStackedColumnSeries(xAxis, yAxis);
stackedColumnSeries1.add(seriesElement1);
stackedColumnSeries1.add(seriesElement2);
stackedColumnSeries1.add(seriesElement3);
// Add indexed 100 percent stacked column series to the plot area
plotArea.getSeries().add(stackedColumnSeries1);
// Adding AxisLabels to the XAxis
stackedColumnSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q1", 0));
stackedColumnSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q2", 1));
stackedColumnSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q3", 2));
stackedColumnSeries1.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" );
}
}