
Circle Graph Maker
This Java API tutorial will teach us how to make a graph in PDF using Java programmatically. You can generate multiple types of graphs using this enterprise-level library. However, in this guide, we will write steps and the code snippet to build a circle graph maker in a Java application. Once you are done with the code snippet, you can automate the graph creation easily. In addition, we will explore some advanced methods exposed by the API we will use in this article.
We will cover the following topics:
- Circle Graph Maker - API installation
- How to make a Graph in PDF using Java
- Generate a filled Circle graph
Circle Graph Maker - API installation
We are going to use this power PDF API for Java. There is a wide range of methods available to meet your business requirements. In fact, you can either download the API or install it using the following Maven configurations.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<classifier>jdk17</classifier>
</dependency>
How to make a Graph in PDF using Java
You may follow the steps and the code snippets mentioned below:
- Create an object of the Document class.
- Invoke the getPages().add() method to add a page to pages collection of PDF file.
- Initializes a new instance of the Graph class with certain dimensions.
- Initialize a new instance of the BorderInfo class.
- Invoke the setBorder method to set the border of the graph.
- Create an instance of the Circle class and specify the parameters.
- Now, call the getGraphInfo().setColor method to set the graph color.
- Add Graph object to paragraphs collection of page by calling the getParagraphs().add(graph) method.
- Invoke the save method to save the PDF file.
Copy & paste the following code into your main file:
// Create an object of the Document class | |
Document pdfDocument = new Document(); | |
// Invoke the getPages().add() method to add page to pages collection of PDF file | |
Page page = pdfDocument.getPages().add(); | |
// Initializes a new instance of the Graph class with certain dimensions | |
Graph graph = new Graph(400, 200); | |
// Initialize a new instance of the BorderInfo class | |
BorderInfo borderInfo = new BorderInfo(BorderSide.All, Color.getGreen()); | |
// Invoke the setBorder method to set the border of the graph | |
graph.setBorder(borderInfo); | |
// Create an instance of the Circle class and specify the parameters | |
Circle circle = new Circle(100,100,40); | |
// Now, call the getGraphInfo().setColor method to set the graph color | |
circle.getGraphInfo().setColor(Color.getGreenYellow()); | |
graph.getShapes().add(circle); | |
// Add Graph object to paragraphs collection of page by calling the getParagraphs().add(graph) method | |
page.getParagraphs().add(graph); | |
// Invoke the save method to save the PDF file | |
pdfDocument.save( "DrawingCircle1_out.pdf"); |
You may see the output in the image below:

Generate a filled Circle graph
The following code snippet is to generate a filled circle graph programmatically:
Copy & paste the following code into your main file:
// Create an object of the Document class | |
Document pdfDocument = new Document(); | |
// Invoke the getPages().add() method to add page to pages collection of PDF file | |
Page page = pdfDocument.getPages().add(); | |
// Initializes a new instance of the Graph class with certain dimensions | |
Graph graph = new Graph(400, 200); | |
// Initialize a new instance of the BorderInfo class | |
BorderInfo borderInfo = new BorderInfo(BorderSide.All, Color.getGreen()); | |
// Invoke the setBorder method to set the border of the graph | |
graph.setBorder(borderInfo); | |
// Create an instance of the Circle class and specify the parameters | |
Circle circle = new Circle(100,100,40); | |
// Now, call the getGraphInfo().setColor method to set the graph color | |
circle.getGraphInfo().setColor(Color.getGreenYellow()); | |
// Invoke the setFillColor method to sets a Color object that indicates the fill color of the graph. https://reference.aspose.com/pdf/java/com.aspose.pdf/GraphInfo#setFillColor-com.aspose.pdf.Color- | |
circle.getGraphInfo().setFillColor(Color.getGreenYellow()); | |
graph.getShapes().add(circle); | |
// Add Graph object to paragraphs collection of page by calling the getParagraphs().add(graph) method | |
page.getParagraphs().add(graph); | |
// Invoke the save method to save the PDF file | |
pdfDocument.save( "DrawingCircle1_out.pdf"); |
You may see the output in the image below:

Get a Free License
You can avail a free temporary license to try the API without evaluation limitations.
Summing up
There are many other methods and provisions offered by this PDF API for Java. We suggest you visit the documentation to know further about this library. So, we have gone through how to make a graph in PDF using Java programmatically. Moreover, this article will really help you if you are looking to build a circle graph maker for your business software.
Moreover, we suggest you follow our Getting Started guide.
Finally, conholdate.com is writing new blog posts. Therefore, please stay in touch for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
FAQs
How do I make graphs in PDF?
Please follow this link to know about the steps and the code snippet to learn how to make a graph in a PDF programmatically.