How to Build a Gantt Chart in Java: A 5-Step Guide with Code
A project plan can be easy to understand in a task list, then suddenly confusing when dates overlap. A Gantt chart makes task timing visible, but building one in Java can feel like a detour through unfamiliar charting APIs.
Without a clear task model, dates and labels can become difficult to maintain. A chart may render correctly while hiding schedule overlaps or displaying unhelpful information.
Here’s the practical route: use JFreeChart, represent each activity as a task with start and end dates, then render and export the chart. I’ll walk you through five steps with working Java code, customization tips, and checks that help you catch common problems before sharing the result.
How to Build a Gantt Chart in Java in 5 Steps
You can create a basic Java Gantt chart with JFreeChart by adding the library, creating task intervals, building a task series, rendering the chart, and exporting it. The example below creates a project schedule and saves it as a PNG image.
Step 1: Add JFreeChart to Your Project
For a Maven project, add the JFreeChart dependency to your pom.xml. This example uses version 1.5.5.
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.5</version>
</dependency>
If you use Gradle, add the corresponding dependency to your build configuration. Keep the library version aligned with your project’s Java version and dependency policies.
Step 2: Create Tasks with Start and End Dates
A Gantt chart represents each activity as a task interval. In JFreeChart, a Task holds a description and a time period.
For example, a small software project might include requirements, implementation, and testing. Each task needs a start date and an end date.
Step 3: Group Tasks into a Series
Create a TaskSeries and add each task to it. Then place the series inside a TaskSeriesCollection, which the chart factory uses to build the schedule view.
Here’s why: separating task creation from chart rendering makes it easier to update schedule details without rewriting the chart setup.
Step 4: Build and Style the Chart
Pass the task collection to ChartFactory.createGanttChart(). You can set the chart title, category axis label, and date axis label when creating it.
After creating the chart, adjust its background and plot settings. Clear labels and subtle gridlines can help readers compare task timing at a glance.
Step 5: Export the Result and Check It
Use ChartUtils.saveChartAsPNG() to export an image. Review the rendered chart to confirm the task names, date range, and interval lengths look right.
The complete example below uses three project activities. It converts ISO-formatted dates to Java dates and saves a 1200-by-600 PNG image.
import java.awt.Color;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.SimpleTimePeriod;
public class GanttChartExample {
private static Date date(String value) {
return Date.from(
LocalDate.parse(value)
.atStartOfDay(ZoneId.of("UTC"))
.toInstant()
);
}
public static void main(String[] args) throws Exception {
TaskSeries project = new TaskSeries("Website launch");
project.add(new Task(
"Requirements",
new SimpleTimePeriod(
date("2025-06-02"),
date("2025-06-06")
)
));
project.add(new Task(
"Implementation",
new SimpleTimePeriod(
date("2025-06-05"),
date("2025-06-17")
)
));
project.add(new Task(
"Testing",
new SimpleTimePeriod(
date("2025-06-16"),
date("2025-06-20")
)
));
TaskSeriesCollection schedule = new TaskSeriesCollection();
schedule.add(project);
JFreeChart chart = ChartFactory.createGanttChart(
"Website Launch Schedule",
"Task",
"Date",
schedule,
true,
true,
false
);
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
ChartUtils.saveChartAsPNG(
Path.of("gantt-chart.png").toFile(),
chart,
1200,
600
);
}
}
In this example, implementation overlaps with requirements, and testing overlaps with implementation. That makes schedule relationships visible, even though the chart does not draw dependency connectors automatically.
Prepare Your Java Gantt Chart Data
Before you create a chart, decide what one bar represents. A bar might represent an individual task, a project phase, or a team’s work package. Choose a level that makes the schedule useful to its audience.
For example, a team planning a product release may use “Design,” “Build,” and “QA” as high-level activities. A project lead who needs to assign responsibility may break “Build” into smaller tasks such as “Create login screen” and “Connect authentication.”
Choose a Consistent Date Convention
Java’s date and time APIs require you to think about time zones and time precision. The example uses UTC and converts each date to the start of that day, keeping the displayed schedule consistent.
If your plan uses working days, weekends, or local business hours, account for those rules before creating the task intervals. JFreeChart displays the dates you provide; it does not automatically know your organization’s calendar.
Represent Milestones Clearly
A milestone is a point in time, while a task usually spans a duration. You can represent a milestone as a short interval or build a separate visual marker, depending on your chart design.
For instance, “Approval received” might be a milestone between implementation and testing. Label it clearly so readers do not mistake it for a multi-day activity.
Customize the Chart for Readability
A chart that renders successfully is only a starting point. Long task names, crowded date labels, and a large number of activities can make a schedule hard to scan.
Try changing the chart dimensions when labels feel cramped. A schedule with 25 activities may need a taller image than the three-task example, while a six-month plan may need more width to show its date axis.
Improve Titles and Axis Labels
Use a title that identifies the project or reporting period, such as “Website Launch Schedule.” Keep axis labels specific. “Task” and “Date” are clear for a small plan, while “Release activity” and “Target period” may fit a business report better.
Choose task descriptions that remain understandable when viewed without extra explanation. “Security review” tells readers more than “Review,” especially when a chart includes work across multiple teams.

Be Careful with Overlapping Work
Overlapping bars can indicate parallel work, but they can also reveal a planning risk. In the example, implementation begins before requirements end, and testing starts before implementation finishes.
That timing may be intentional if the team works in stages. If it is not, adjust the dates before publishing the chart. A clear visual can expose scheduling assumptions that a task list might hide.
Export, Share, and Maintain the Schedule
JFreeChart can export a chart image for reports, dashboards, or presentations. The PNG export in the example works well when readers need a fixed visual rather than an interactive schedule.
If your plan changes often, regenerate the chart from the current task details instead of editing the image manually. For example, when testing moves from June 16 to June 19, update the task interval and create a new chart.
Choose an Output Format That Fits the Use
PNG is convenient for web pages and presentations. Other formats may suit print layouts or applications that need interactive chart behavior, so confirm the needs of your destination before choosing an export path.
Keep a predictable chart size and title style across recurring reports. That consistency helps readers compare one project update with the next without learning a new visual format each time.
Check the Rendered Result
Open the exported image and inspect the axis labels, task names, and date intervals. Check the chart at the size people will actually view it, especially if it will appear in a narrow web page or a presentation slide.
For example, a 1200-pixel image may look readable on a desktop but become difficult to scan when reduced to 500 pixels. Increase the image dimensions or reduce label length when that happens.
Java Gantt Chart Solution: ONES.com
ONES.com is a unified platform for project management and knowledge management, powered by ONES Assistant. ONES Project supports project workflows; ONES Wiki provides knowledge management, and the two products are sold separately.

If you are writing Java code to generate a Gantt-style visual, JFreeChart handles the chart-rendering task. ONES.com addresses a different need: organizing project work, workflows, and team knowledge around the schedule.
Core Capabilities
- Scattered project tasks: ONES Project provides project management capabilities, giving teams a place to coordinate work and follow progress.
- Jira workflow migration: Jira-compatible workflows help teams carry familiar processes into a Jira alternative.
- Custom process requirements: Custom workflows and fields let teams reflect how work moves through their organization.
- Sprint planning needs: Sprint management supports teams that plan and review work in recurring development cycles.
- Manual repetitive actions: Automation can reduce routine workflow handling and help teams keep processes moving.
- Limited progress visibility: Built-in reporting helps teams review project activity without assembling every update by hand.
- Tool sprawl: A unified project and knowledge management platform can connect work coordination with team knowledge, while ONES Project and ONES Wiki remain separately sold products.
- Deployment restrictions: Cloud, On-Premise, Private Cloud, and Air-gapped deployments give organizations deployment choices. The cloud and self-hosted versions have full feature parity.
Application Scenarios
A Java development team could use ONES Project to coordinate sprint work while maintaining a custom JFreeChart view for a specific report. The team can manage activities in its project workflow and generate a chart image for stakeholders who need a compact visual.
An organization with restricted network requirements may evaluate an On-Premise, Private Cloud, or Air-gapped deployment. Teams can keep project management within their deployment environment while building Java-based reporting for internal schedules.
ONES.com offers a free plan for up to 30 seats. Consider it when the need extends beyond rendering a chart to managing project workflows and shared knowledge across a team.
Common Challenges When Creating Gantt Charts in Java
- Dates appear shifted: Time zones can move displayed intervals when dates are converted inconsistently. Choose a time zone deliberately, then apply the same convention to every task.
- Task labels are difficult to read: Long names can crowd the chart. Use concise, recognizable labels and adjust chart dimensions for larger schedules.
- Bars overlap unexpectedly: Overlap may reflect parallel work or incorrect dates. Review the plan with the people responsible for the activities before sharing it.
- Readers expect dependency arrows: A basic JFreeChart Gantt chart displays task intervals, but it does not automatically show dependency connectors. Explain relationships in a companion view or implement additional chart behavior.
- The image becomes stale: A static PNG does not update when dates change. Regenerate the chart whenever the schedule is revised, and verify the new image before distributing it.
Frequently Asked Questions
Can I create a Gantt chart in Java without JFreeChart?
Yes. You can draw a chart with Java’s graphics APIs or use another charting library. JFreeChart is a practical choice when you want established chart components and PNG export. If you need interactive editing, dependency connectors, or specialized timeline behavior, compare libraries against those requirements before committing to an implementation.
Does JFreeChart automatically show task dependencies?
The basic Gantt chart example shows task intervals on a timeline. It does not automatically draw dependency arrows between tasks. You can explain relationships with labels or add custom rendering behavior. For a project where dependency paths are essential, consider whether a specialized scheduling component better fits your needs.
How do I make a Java Gantt chart show overlapping tasks?
Give each task its own start and end dates, including the overlapping periods. The example starts implementation before requirements end, so their bars overlap on the timeline. Check that the overlap reflects the real plan, then inspect the rendered chart to confirm the date axis makes it visible.
Can I export a Java Gantt chart as an image?
Yes. JFreeChart’s ChartUtils.saveChartAsPNG() method saves a chart as a PNG image. Set a suitable width and height for the place where the image will appear. Open the exported image afterward, because task names and dates that look clear in a large view may become cramped when resized.
Conclusion
You can create a Java Gantt chart by modeling task intervals, grouping them in a JFreeChart task series, rendering the chart, and exporting the result. The five-step example gives you a working starting point, including overlapping tasks and PNG output.
When schedules become difficult to read, improve the date conventions, labels, and chart dimensions before sharing the image. If your broader challenge is coordinating work and team knowledge, ONES.com offers project and knowledge management capabilities alongside your custom Java reporting.
A clear schedule makes timing easier to understand. Start with a few real tasks, check the rendered result, and refine the chart until it answers the questions your team actually has.