Visualizing project timelines helps teams stay aligned and meet deadlines. Conholdate.Total for Java provides a robust SDK that makes it easy to create Gantt Chart in Java with just a few lines of code. In this guide you’ll see how to set up the library, define tasks, customize the appearance, and export the chart to PDF.
Setting Up Conholdate.Total for Java
Before you start coding, ensure you have Java 17 or later and a Maven‑compatible IDE. Add the Conholdate Maven repository and the SDK dependency to your pom.xml:
<repositories>
<repository>
<id>conholdate-repo</id>
<name>Conholdate Maven Repository</name>
<url>https://repository.conholdate.com/repo/</url>
</repository>
</repositories>
<dependency>
<groupId>com.conholdate</groupId>
<artifactId>conholdate-total</artifactId>
<version>24.9</version>
<type>pom</type>
</dependency>
You can also download the latest JARs directly from the download page. Once the SDK is on your classpath, you’re ready to start building the chart.
Building It Step by Step: Create Gantt Chart in Java
Step 1: Configure Chart Options
First, create a GanttChartOptions instance and set the visual properties you need. This object controls the title, timeline scale, bar colors, and more.
GanttChartOptions options = new GanttChartOptions();
options.setTitle("Project Development Schedule");
options.setScale(GanttScale.DAYS);
options.setBarColor(GanttBarColor.BLUE);
options.setBarPattern(GanttBarPattern.SOLID);
options.setBarStyle(GanttBarStyle.RECTANGLE);
options.setEnableCaching(true);
For detailed property descriptions, refer to the GanttChartOptions API.
Step 2: Create the GanttChart Instance
Pass the configured options to the GanttChart constructor.
GanttChart chart = new GanttChart(options);
The chart object now holds the layout engine ready to receive tasks.
Step 3: Add Tasks to Build the Timeline
Use chart.addTask to insert each project phase. Adding tasks is the core of how you create Gantt Chart in Java, because each task defines a start and end date.
chart.addTask("Requirement Analysis", toDate(2023, 10, 1), toDate(2023, 10, 5));
chart.addTask("Design", toDate(2023, 10, 6), toDate(2023, 10, 12));
chart.addTask("Implementation", toDate(2023, 10, 13), toDate(2023, 11, 5));
chart.addTask("Testing", toDate(2023, 11, 6), toDate(2023, 11, 20));
chart.addTask("Deployment", toDate(2023, 11, 21), toDate(2023, 11, 22));
The helper method toDate converts a year/month/day triple into a java.util.Date object.
Step 4: Export the Chart
Finally, save the chart to a file. The SDK supports PDF, PNG, JPEG and other formats.
chart.save("output/gantt_chart.pdf", SaveFormat.PDF);
You can change SaveFormat.PDF to SaveFormat.PNG or SaveFormat.JPEG if you need a different output.
Step 5: Clean Up Resources
Release native resources once you’re done.
chart.dispose();
Complete Code Example: Gantt Chart Java Example
The following example demonstrates how to create a Gantt Chart in Java from start to finish.
import com.groupdocs.chart.GanttChart;
import com.groupdocs.chart.options.GanttChartOptions;
import com.groupdocs.chart.enums.GanttScale;
import com.groupdocs.chart.enums.GanttBarColor;
import com.groupdocs.chart.enums.GanttBarPattern;
import com.groupdocs.chart.enums.GanttBarStyle;
import com.groupdocs.chart.enums.SaveFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
public class GanttChartDemo {
public static void main(String[] args) {
// Configure chart appearance and timeline scale
GanttChartOptions options = new GanttChartOptions();
options.setTitle("Project Development Schedule");
options.setScale(GanttScale.DAYS); // timeline scale
options.setBarColor(GanttBarColor.BLUE); // default bar color
options.setBarPattern(GanttBarPattern.SOLID); // bar fill pattern
options.setBarStyle(GanttBarStyle.RECTANGLE); // bar shape
options.setEnableCaching(true); // performance for large charts
// Create the Gantt chart with the defined options
GanttChart chart = new GanttChart(options);
// Populate chart with tasks (dynamic data source can be used similarly)
chart.addTask("Requirement Analysis", toDate(2023, 10, 1), toDate(2023, 10, 5));
chart.addTask("Design", toDate(2023, 10, 6), toDate(2023, 10, 12));
chart.addTask("Implementation", toDate(2023, 10, 13), toDate(2023, 11, 5));
chart.addTask("Testing", toDate(2023, 11, 6), toDate(2023, 11, 20));
chart.addTask("Deployment", toDate(2023, 11, 21), toDate(2023, 11, 22));
// Export the Gantt chart to PDF (other formats like PNG, JPEG are also supported)
chart.save("output/gantt_chart.pdf", SaveFormat.PDF);
// Release resources
chart.dispose();
}
// Helper method to convert year/month/day to java.util.Date
private static Date toDate(int year, int month, int day) {
return Date.from(
LocalDate.of(year, month, day)
.atStartOfDay(ZoneId.systemDefault())
.toInstant()
);
}
}
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
Conclusion
Creating a Gantt Chart in Java becomes straightforward with Conholdate.Total for Java. By configuring GanttChartOptions, adding tasks, and exporting the result, you can generate professional‑looking timelines in seconds. The SDK’s caching feature and flexible SaveFormat options help you handle large projects efficiently. Remember that a commercial license is required for production deployments; you can obtain a temporary license from the temporary license page or explore pricing details on the pricing page. Start integrating Gantt charts into your applications today and keep your stakeholders informed with clear visual schedules.
FAQs
How do I create Gantt Chart in Java using Conholdate.Total?
Use the GanttChart and GanttChartOptions classes, add your tasks with addTask, and call save to export. The full code Snippet is provided in this article.
Can I export the Gantt chart to formats other than PDF?
Yes. The chart.save method accepts SaveFormat.PNG, SaveFormat.JPEG, and other values defined in the SaveFormat enum. See the official documentation for the complete list.
What licensing is required for production use?
A commercial license is mandatory. You can request a temporary license from the temporary license page and review pricing on the pricing page.
How can I improve performance for large Gantt charts?
Enable caching with options.setEnableCaching(true) and keep the number of tasks reasonable. The SDK is optimized for large data sets, and caching reduces rendering time significantly.
