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, populate task data in a worksheet, turn a stacked bar chart into a Gantt-style timeline, and export the result to Excel.

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: Create the Workbook and Populate Task Data

A Gantt chart built this way is really a stacked bar chart layered on top of worksheet data, so the first step is to create the Workbook, grab the first Worksheet, and fill in the task names, start offsets, and durations that the chart will read from.

com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook();
com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);

com.aspose.cells.Cells cells = sheet.getCells();
cells.get("A1").putValue("Task");
cells.get("C1").putValue("Duration (Days)");
cells.get("D1").putValue("Start Offset (Days)");

cells.get("A2").putValue("Requirement Analysis");
cells.get("C2").putValue(5);
cells.get("D2").putValue(0);

cells.get("A3").putValue("Design");
cells.get("C3").putValue(7);
cells.get("D3").putValue(5);

cells.get("A4").putValue("Implementation");
cells.get("C4").putValue(24);
cells.get("D4").putValue(12);

cells.get("A5").putValue("Testing");
cells.get("C5").putValue(15);
cells.get("D5").putValue(36);

cells.get("A6").putValue("Deployment");
cells.get("C6").putValue(2);
cells.get("D6").putValue(51);

Column A holds the task name, column C holds how many days each task takes, and column D holds how many days after the project start each task begins. The chart’s two series (start offset and duration) are read straight from columns D and C.

Step 2: Add a Stacked Bar Chart and Configure the Series

With the data in place, add a BAR_STACKED chart to the worksheet and wire up its series. The start-offset series pushes each task bar to the right; the duration series draws the visible task bar on top of it.

int chartIndex = sheet.getCharts().add(com.aspose.cells.ChartType.BAR_STACKED, 7, 0, 30, 10);
com.aspose.cells.Chart chart = sheet.getCharts().get(chartIndex);
chart.getTitle().setText("Gantt Chart");

// Add offset and duration as series
chart.getNSeries().add("D2:D6", true); // Start Offset
chart.getNSeries().add("C2:C6", true); // Duration

// Set task names as categories
chart.getNSeries().setCategoryData("A2:A6");

The chart is anchored to the worksheet at row 7, column 0, and spans 30 rows by 10 columns.

Step 3: Style the Chart to Look Like a Gantt Chart

The trick to a stacked bar chart reading as a Gantt chart is making the offset series invisible so only the duration bars show, floating at the correct start position.

// Make offset bars invisible
chart.getNSeries().get(0).getArea().setFormatting(com.aspose.cells.FormattingType.NONE);

// Style duration bars
chart.getNSeries().get(1).getArea().setFormatting(com.aspose.cells.FormattingType.CUSTOM);
chart.getNSeries().get(1).getArea().setForegroundColor(com.aspose.cells.Color.getSteelBlue());
chart.getNSeries().get(1).getDataLabels().setShowValue(true);

Step 4: Configure Axes, Legend, and Size

Reverse the category axis so the first task appears at the top, label both axes, and turn off the legend since there’s only one meaningful series to read.

// Axis settings
chart.getCategoryAxis().setPlotOrderReversed(true);
chart.getCategoryAxis().getTitle().setText("Tasks");
chart.getValueAxis().getTitle().setText("Days from Start");
chart.getValueAxis().getMajorGridLines().setVisible(true);

// Hide legend
chart.setShowLegend(false);

// Resize chart
chart.getChartObject().setWidth(700);
chart.getChartObject().setHeight(400);

Step 5: Save the Workbook

Finally, save the workbook. The SDK supports XLSX, XLS, and other formats listed in the SaveFormat enum.

// Save the result
workbook.save("GanttChartResult.xlsx", com.aspose.cells.SaveFormat.XLSX);

Open GanttChartResult.xlsx in Excel (or any compatible spreadsheet app) to see the finished Gantt chart embedded on the worksheet.

Complete Code Example: Gantt Chart Java Example

The following example demonstrates how to create a Gantt Chart in Java from start to finish.

public class GanttChartDemo {
    public static void main(String[] args) {
        // Create the workbook and get the first worksheet
        com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook();
        com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);

        // Populate task names, durations, and start offsets
        com.aspose.cells.Cells cells = sheet.getCells();
        cells.get("A1").putValue("Task");
        cells.get("C1").putValue("Duration (Days)");
        cells.get("D1").putValue("Start Offset (Days)");

        cells.get("A2").putValue("Requirement Analysis");
        cells.get("C2").putValue(5);
        cells.get("D2").putValue(0);

        cells.get("A3").putValue("Design");
        cells.get("C3").putValue(7);
        cells.get("D3").putValue(5);

        cells.get("A4").putValue("Implementation");
        cells.get("C4").putValue(24);
        cells.get("D4").putValue(12);

        cells.get("A5").putValue("Testing");
        cells.get("C5").putValue(15);
        cells.get("D5").putValue(36);

        cells.get("A6").putValue("Deployment");
        cells.get("C6").putValue(2);
        cells.get("D6").putValue(51);

        // Add a stacked bar chart that will act as the Gantt chart
        int chartIndex = sheet.getCharts().add(com.aspose.cells.ChartType.BAR_STACKED, 7, 0, 30, 10);
        com.aspose.cells.Chart chart = sheet.getCharts().get(chartIndex);
        chart.getTitle().setText("Gantt Chart");

        // Add offset and duration as series
        chart.getNSeries().add("D2:D6", true); // Start Offset
        chart.getNSeries().add("C2:C6", true); // Duration

        // Set task names as categories
        chart.getNSeries().setCategoryData("A2:A6");

        // Make offset bars invisible
        chart.getNSeries().get(0).getArea().setFormatting(com.aspose.cells.FormattingType.NONE);

        // Style duration bars
        chart.getNSeries().get(1).getArea().setFormatting(com.aspose.cells.FormattingType.CUSTOM);
        chart.getNSeries().get(1).getArea().setForegroundColor(com.aspose.cells.Color.getSteelBlue());
        chart.getNSeries().get(1).getDataLabels().setShowValue(true);

        // Axis settings
        chart.getCategoryAxis().setPlotOrderReversed(true);
        chart.getCategoryAxis().getTitle().setText("Tasks");
        chart.getValueAxis().getTitle().setText("Days from Start");
        chart.getValueAxis().getMajorGridLines().setVisible(true);

        // Hide legend
        chart.setShowLegend(false);

        // Resize chart
        chart.getChartObject().setWidth(700);
        chart.getChartObject().setHeight(400);

        // Save the result
        workbook.save("GanttChartResult.xlsx", com.aspose.cells.SaveFormat.XLSX);
    }
}

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 populating task data in a worksheet, adding a stacked bar chart, and styling its series and axes, you can generate professional‑looking timelines that live right inside an Excel file. Hiding the start-offset series while styling the duration series is the key technique that turns an ordinary stacked bar chart into a Gantt chart. 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?
Create a Workbook, add a BAR_STACKED chart to a worksheet, and add two series: a hidden start-offset series and a visible duration series. Set the task names as category data, style the visible series, and save the workbook. The full code Snippet is provided in this article.

Can I export the Gantt chart to formats other than Excel?
Yes. Since the chart is embedded in a workbook, you can save the file using any value from the SaveFormat enum, such as XLSX, XLS, or ODS. 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?
Keep the data range referenced by each series as tight as possible, avoid unnecessary workbook recalculation, and limit formatting calls to the series and axes you actually need. Keeping the number of tasks per chart reasonable also keeps rendering fast for large project files.

Read More