Example: The following example creates a indexed line value 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.*;
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, 230);
// 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 x Axis
IndexedXAxis xAxis = new IndexedXAxis();
// Create a numeric y Axis
NumericYAxis yAxis = new NumericYAxis();
// Create a indexed line series and add values to it
IndexedLineSeries lineSeries1 = new IndexedLineSeries("Website A", xAxis, yAxis);
lineSeries1.getValues().add(new IndexedLineValue(5, 0));
lineSeries1.getValues().add(new IndexedLineValue(7, 1));
lineSeries1.getValues().add(new IndexedLineValue(9, 2));
lineSeries1.getValues().add(new IndexedLineValue(6, 3));
IndexedLineSeries lineSeries2 = new IndexedLineSeries("Website B", xAxis, yAxis);
lineSeries2.getValues().add(new IndexedLineValue(4, 0));
lineSeries2.getValues().add(new IndexedLineValue(2, 1));
lineSeries2.getValues().add(new IndexedLineValue(5, 2));
lineSeries2.getValues().add(new IndexedLineValue(8, 3));
IndexedLineSeries lineSeries3 = new IndexedLineSeries("Website C", xAxis, yAxis);
lineSeries3.getValues().add(new IndexedLineValue(2, 0));
lineSeries3.getValues().add(new IndexedLineValue(4, 1));
lineSeries3.getValues().add(new IndexedLineValue(6, 2));
lineSeries3.getValues().add(new IndexedLineValue(9, 3));
// add indexed line series to the plot Area
plotArea.getSeries().add(lineSeries1);
plotArea.getSeries().add(lineSeries2);
plotArea.getSeries().add(lineSeries3);
// Create a title and add it to the yaxis
Title lTitle = new Title("Visitors (in millions)");
lineSeries1.getYAxis().getTitles().add(lTitle);
// adding AxisLabels to the XAxis
lineSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q1", 0));
lineSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q2", 1));
lineSeries1.getXAxis().getLabels().add(new IndexedXAxisLabel("Q3", 2));
lineSeries1.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");
}
}