This quick tutorial explains the process to create Gantt chart in Excel using C#. It has the IDE settings, a list of instructions, and a sample code to develop Gantt chart in Excel using C#. You will get detailed code where sample code is created programmatically to demonstrate the complete process without any external data source.
Steps to Build a Gantt Chart in Excel using C#
- Set the environment to use Aspose.Cells for .NET to create a Gantt chart
- Instantiate the license, create a new Excel file using the Workbook class , and rename the first sheet
- Define the list of sample project tasks with start/finish dates for the Gantt chart
- Set the table headers for work item, start, finish, Start offset, duration
- Calculate the initial start date as a baseline and insert each task row with the offset and duration
- Format the sheet columns to auto-fit the Start and Finish dates
- Set the custom data ranges for task names, offset series, and duration series in the Gantt chart
- Add a stacked bar chart, create floating bars by hiding the offset series, and set style for bars and legend
- Reverse the category axis, set label for the value axis, set the plot styling, and save the resultant Workbook
The above steps describe the process to create Gantt chart. Create a workbook, set Gantt chart task table, and calculate the start offsets and durations using the earliest date to plot the timeline. Finally, insert a stacked bar chart, hide the offset series for creating the floating Gantt bars, set the basic styling, and save the Excel file.
Code to Construct a Gantt Chart using C#
This code demonstrates the process to create Gantt diagram using C#. For further improvisations, auto-fit the worksheet columns, freeze the header row, and apply a built-in table style to the data ranges for better visualization. Options are also available for adding data labels, customizing axis titles, and exporting a chart image to enhance presentation.
This article has taught us the process to create a Gantt chart. For creating a Stock chart, refer to the article Create Stock Chart in Excel using C#.