Example: The following example creates a indexed Stacked bar series chart and adds values to it.
import com.cete.dynamicpdf.Document;
import com.cete.dynamicpdf.Page;
import com.cete.dynamicpdf.pageelements.charting.*;
import com.cete.dynamicpdf.pageelements.charting.series.*;
import com.cete.dynamicpdf.pageelements.charting.values.*;
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();
// 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 numeric x axis
NumericXAxis xAxis = new NumericXAxis();
// Create a indexed y axis
IndexedYAxis yAxis = new IndexedYAxis();
// Create a indexed stacked bar series and add values to it
IndexedStackedBarSeriesElement seriesElement1 = new IndexedStackedBarSeriesElement("Website A");
seriesElement1.getValues().add(new IndexedStackedBarValue(5, 0));
seriesElement1.getValues().add(new IndexedStackedBarValue(7, 1));
seriesElement1.getValues().add(new IndexedStackedBarValue(9, 2));
seriesElement1.getValues().add(new IndexedStackedBarValue(6, 3));
IndexedStackedBarSeriesElement seriesElement2 = new IndexedStackedBarSeriesElement("Website B");
seriesElement2.getValues().add(new IndexedStackedBarValue(4, 0));
seriesElement2.getValues().add(new IndexedStackedBarValue(2, 1));
seriesElement2.getValues().add(new IndexedStackedBarValue(5, 2));
seriesElement2.getValues().add(new IndexedStackedBarValue(8, 3));
IndexedStackedBarSeriesElement seriesElement3 = new IndexedStackedBarSeriesElement("Website C");
seriesElement3.getValues().add(new IndexedStackedBarValue(2, 0));
seriesElement3.getValues().add(new IndexedStackedBarValue(4, 1));
seriesElement3.getValues().add(new IndexedStackedBarValue(6, 2));
seriesElement3.getValues().add(new IndexedStackedBarValue(8, 3));
// Create a indexed stacked bar series and add indexed stacked bar series elements to it
IndexedStackedBarSeries stackedBarSeries1 = new IndexedStackedBarSeries(xAxis, yAxis);
stackedBarSeries1.add(seriesElement1);
stackedBarSeries1.add(seriesElement2);
stackedBarSeries1.add(seriesElement3);
// add indexed stacked bar series to the plot area
plotArea.getSeries().add(stackedBarSeries1);
// Create a title and add it to the yaxis
Title lTitle = new Title("Visitors (in millions)");
stackedBarSeries1.getXAxis().getTitles().add(lTitle);
// adding AxisLabels to the XAxis
stackedBarSeries1.getYAxis().getLabels().add(new IndexedYAxisLabel("Q1", 0));
stackedBarSeries1.getYAxis().getLabels().add(new IndexedYAxisLabel("Q2", 1));
stackedBarSeries1.getYAxis().getLabels().add(new IndexedYAxisLabel("Q3", 2));
stackedBarSeries1.getYAxis().getLabels().add(new IndexedYAxisLabel("Q4", 3));
// add the chart to the page
page.getElements().add(chart);
document.getPages().add(page);
// Save the PDF
document.draw("[PhysicalPath]/MyDocument.pdf" );
}
}