Example: The following example will place a chart, add several lines into the Title object and add titles to the chart. Add values into IndexedBarSeriesElements objects, add indexed bar series elements to the indexed bar series object.Add indexed bar series to the plot area. Add Yaxis to the title and axislabels to the Xaxis.Then add the chart to the page.
import com.cete.dynamicpdf.Document; import com.cete.dynamicpdf.Page; import com.cete.dynamicpdf.RgbColor; import com.cete.dynamicpdf.pageelements.charting.Chart; import com.cete.dynamicpdf.pageelements.charting.PlotArea; import com.cete.dynamicpdf.pageelements.charting.Title; import com.cete.dynamicpdf.pageelements.charting.XYScatterDataLabel; import com.cete.dynamicpdf.pageelements.charting.series.XYScatterSeries; 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, 450, 230); //Get the default plot area from the chart PlotArea plotArea = chart.getPrimaryPlotArea(); // Create a Header title and add it to the chart Title tTitle = new Title("Player Height and Weight"); chart.getHeaderTitles().add(tTitle); // Create xyScatter series and add values to it XYScatterSeries xyScatterSeries1 = new XYScatterSeries("Team A"); xyScatterSeries1.getValues().add(112, 55); xyScatterSeries1.getValues().add(125, 60); xyScatterSeries1.getValues().add(138, 68); xyScatterSeries1.getValues().add(150, 73); xyScatterSeries1.getValues().add(172, 82); XYScatterSeries xyScatterSeries2 = new XYScatterSeries("Team B"); xyScatterSeries2.getValues().add(110, 54); xyScatterSeries2.getValues().add(128, 62); xyScatterSeries2.getValues().add(140, 70); xyScatterSeries2.getValues().add(155, 75); xyScatterSeries2.getValues().add(170, 80); // Create xyscatter data label XYScatterDataLabel dataLabel = new XYScatterDataLabel(true); xyScatterSeries1.setDataLabel(dataLabel); dataLabel.setColor(RgbColor.getRed()); // Add xyScatter series to the plot Area plotArea.getSeries().add(xyScatterSeries1); plotArea.getSeries().add(xyScatterSeries2); // Create axis titles and add it to the axis Title title1 = new Title("Height (Inches)"); Title title2 = new Title("Weight (Pounds)"); xyScatterSeries1.getYAxis().getTitles().add(title1); xyScatterSeries1.getXAxis().getTitles().add(title2); // Add the chart to the page page.getElements().add(chart); // Save the PDF document.draw("[PhysicalPath]/MyDocument.pdf" ); } }