How to create a Gantt chart

What is Gantt chart

A Gantt chart is a type of bar chart that illustrates a project schedule. It shows the start and finish dates of the various elements of a project. Each task or activity is represented by a bar, with its length corresponding to its duration. Gantt charts also indicate dependencies between tasks, allowing project managers to visualize the sequence in which tasks need to be completed. They are widely used in project management to plan, schedule, and track projects effectively.

How to Create a Gantt Chart in Excel

You can create a Gantt chart in Excel by following these steps:

  1. Add some data for Gantt chart.

  2. Select the data and and go to Insert –> Charts –> Insert Column or Bar Chart –> Stacked Bar Chart. In our example, that’s B1:B7, and then Insert Stacked Bar chart.

  3. Selett the chart,Select Data->Add, set the Series name and Series values as following.

  4. Select the chart, edit the Horizontal(Category) Axis Labels.

  5. Format Axis the Y Axis, select Categories in reverse order.

  6. Seletct the Blue Series and set the Fill->NO Fill.

  7. Format Axis the X Axis, set the Mininum and Maxinum(1/5/2019:43470,1/30/2019:43494).

  8. Add Data labels for the chart, now you will get a gantt chart.

How to Add a Gantt Chart in Aspose.Cells for Python Excel Library

Please see the following sample code. It loads the sample Excel file that contains some sample data. It then creates the stacked bar chart based on the initial data and sets relevant properties. Finally, it saves the workbook to output XLSX format. The following screenshot shows the Gantt chart created by Aspose.Cells for Python via .NET in the output Excel file.

Sample Code

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import FillType
# Create an instance of Workbook
workbook = Workbook("sample.xlsx")
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Create BarStacked Chart
i = worksheet.charts.add(ChartType.BAR_STACKED, 5, 6, 20, 15)
# Retrieve the Chart object
chart = worksheet.charts[i]
# Set the chart title name
chart.title.text = "Gantt Chart"
# Set the chart title is Visible
chart.title.is_visible = True
# Set data range
chart.set_chart_data_range("B1:B6", True)
# Add series data range
chart.n_series.add("C2:C6", True)
# No fill for one serie
chart.n_series[0].area.fill_format.fill_type = FillType.NONE
# Set the Horizontal(Category) Axis
chart.n_series.category_data = "A2:A6"
# Reverse the Horizontal(Category) Axis
chart.category_axis.is_plot_order_reversed = True
# Set the value axis's MinValue and MaxValue
chart.value_axis.min_value = worksheet.cells.get("B2").value
chart.value_axis.max_value = worksheet.cells.get("D6").value
chart.plot_area.area.fill_format.fill_type = FillType.NONE
# Show the DataLabels
chart.n_series[1].data_labels.show_value = True
# Disable the Legend
chart.show_legend = False
# Save the result
workbook.save("result.xlsx")