Using the Chart class to create scatter plot with trendline

PDF pdf = new PDF();
Font f1 = new Font(pdf, "Helvetica-Bold");
Font f2 = new Font(pdf, "Helvetica-Bold");
Font f3 = new Font(pdf, "Helvetica-Bold");
Font f4 = new Font(pdf, "Helvetica");
// Please note:
// All font and image objects must be created
// before the first page object.

Page page = new Page(pdf, Letter.PORTRAIT);
f1.setSize(10);
f2.setSize(8);
f3.setSize(7);
f4.setSize(7);

Chart chart = new Chart(f1, f2);
chart.setTitle("World View - Communications");
chart.setXAxisTitle("Cell phones per capita");
chart.setYAxisTitle("Internet users % of the population");

chart.setData(getData("data/world-communications.txt", "|"));
addTrendLine(chart);

chart.setPosition(70, 50);
chart.setSize(500, 300);
chart.drawOn(page);

addTableToChart(page, chart, f3, f4);

pdf.wrap();
pdf.save("Example_09.pdf");
Example_09.java Example_09.pdf

© 2007 Innovatics Inc.