How to Create a Gantt Chart in C#: Step-by-Step Guide (2026)
A Gantt chart can make a project schedule easier to understand, but building one in C# can become frustrating quickly. Dates shift, task bars fall out of alignment, and a chart that looked clear with three tasks becomes crowded with thirty.
That can leave you spending more time fixing the visualization than using it to plan the work. The solution is to start with a reliable task model, calculate dates and bar positions consistently, then render the timeline in a format you can test.
In this guide, I’ll walk you through creating a basic Gantt chart in C# with SVG. You’ll build a small schedule, draw task bars, add a weekly timeline, and learn what to improve before using the chart in a real project.
How to Create a Gantt Chart in C#: Step by Step
The quickest practical route is to represent each task with a name, start date, and duration, then convert those values into SVG coordinates. Follow these steps to create a working chart you can extend.
-
Define what each task needs. Start with a task name, a start date, and a duration in days. For example, “Design” might start on March 2 and take five days.
-
Choose a rendering format. SVG works well for a first implementation because it draws shapes and text in a browser without a charting package. You can later use the same schedule model with a UI framework or a chart library.
-
Convert dates into horizontal positions. Find the earliest task start date. Subtract that date from each task’s start date, then multiply the difference by the width of one day.
-
Draw the timeline and task bars. The example below creates a small SVG chart. It uses weekly grid lines, one row per task, and a colored rectangle to show each duration.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
var tasks = new List<WorkItem>
{
new("Design", new DateOnly(2026, 3, 2), 5),
new("Build", new DateOnly(2026, 3, 7), 10),
new("Test", new DateOnly(2026, 3, 17), 7)
};
var firstDay = tasks.Min(task => task.Start);
var lastDay = tasks.Max(task => task.Start.AddDays(task.DurationDays));
var dayCount = lastDay.DayNumber - firstDay.DayNumber;
const int labelWidth = 150;
const int topMargin = 45;
const int rowHeight = 42;
const int dayWidth = 28;
var chartWidth = labelWidth + dayCount * dayWidth + 30;
var chartHeight = topMargin + tasks.Count * rowHeight + 25;
var svg = new StringBuilder();
svg.AppendLine(
$"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{chartWidth}\" height=\"{chartHeight}\" viewBox=\"0 0 {chartWidth} {chartHeight}\">");
svg.AppendLine("<style>text{font:13px Arial,sans-serif}.grid{stroke:#d8dee8;stroke-width:1}.bar{fill:#4f75d2}</style>");
for (var day = 0; day <= dayCount; day += 7)
{
var x = labelWidth + day * dayWidth;
var date = firstDay.AddDays(day).ToString("MMM d", CultureInfo.InvariantCulture);
svg.AppendLine(
$"<line class=\"grid\" x1=\"{x}\" y1=\"25\" x2=\"{x}\" y2=\"{chartHeight - 10}\" />");
svg.AppendLine(
$"<text x=\"{x + 4}\" y=\"18\">{date}</text>");
}
for (var index = 0; index < tasks.Count; index++)
{
var task = tasks[index];
var offset = task.Start.DayNumber - firstDay.DayNumber;
var x = labelWidth + offset * dayWidth;
var y = topMargin + index * rowHeight;
var barWidth = task.DurationDays * dayWidth;
var safeName = WebUtility.HtmlEncode(task.Name);
svg.AppendLine(
$"<text x=\"10\" y=\"{y + 20}\">{safeName}</text>");
svg.AppendLine(
$"<rect class=\"bar\" x=\"{x}\" y=\"{y}\" width=\"{barWidth}\" height=\"24\" rx=\"4\" />");
}
svg.AppendLine("</svg>");
Console.WriteLine(svg.ToString());
record WorkItem(string Name, DateOnly Start, int DurationDays);
-
View and verify the result. Run the program and copy the printed SVG markup into an HTML page to preview it in a browser. Check that each task starts on the intended date and has the expected bar length.
-
Improve the chart for your project. Add validation, task dependencies, progress indicators, or interactive controls only after the basic timeline renders correctly. Each feature should be backed by a clear requirement.
Here’s why: the task schedule and the drawing are separate concerns. When you adjust a task date, the chart recalculates its position instead of relying on manually placed bars.
How the C# Gantt Chart Works
The chart maps a calendar schedule onto a two-dimensional canvas. Dates determine horizontal positions, while task order determines vertical positions.
Turn calendar dates into chart coordinates
In the example, firstDay sets the timeline’s left edge. A task starting three days later receives an offset of three, multiplied by the width assigned to each day.
For instance, if one day occupies 28 pixels, a task beginning three days after the first date starts 84 pixels to the right. Its duration determines the rectangle’s width.
Use one row per task
Each task gets a vertical position based on its place in the list. With a row height of 42 pixels, task four appears 126 pixels below the first task.
The label sits to the left of the timeline, while the colored rectangle marks the scheduled period. This separation makes the chart easier to scan as task names grow longer.
Why SVG is a useful starting point
SVG keeps the first version lightweight. It scales cleanly in a browser, supports text and shapes, and lets you inspect the generated markup when a bar appears in the wrong position.
But here's the truth: SVG does not provide scheduling rules for you. You still need to decide how to treat weekends, milestones, task dependencies, and dates that fall outside the visible timeline.
Make the Timeline Accurate and Readable
A chart can render without errors and still mislead the people using it. Date conventions, task order, and visual clarity all affect whether someone can trust the schedule.
Decide whether duration counts working days
The sample counts calendar days, including weekends. If a five-day task starts on Friday, its bar spans through Tuesday under that rule.
If your team plans in working days, calculate business days instead. For example, a task starting Friday with a five-workday duration should skip Saturday and Sunday when determining its end date.
Handle milestones and dependencies deliberately
A milestone has no duration, so a rectangle with zero width will be invisible. Render milestones as diamonds or vertical markers, and label them clearly.
For dependencies, store relationships between tasks and validate them before rendering. If “Test” depends on “Build,” the chart should make it easy to spot a test period scheduled before the build is complete.
Make dense schedules easier to scan
Long project names can collide with bars, while a timeline with daily labels may become cluttered. Use a fixed label area and show dates at intervals that match the chart’s scale.
For a six-week project, weekly labels may be enough. For a two-day maintenance window, daily or hourly labels will be more useful.
Test and Extend Your Gantt Chart
Test the schedule calculations separately from the visual rendering. A few targeted checks can catch date and layout problems before the chart is used for planning.
Check boundary cases
Try a task that starts on the earliest date, one that ends on the final date, and a task that starts between weekly tick marks. Confirm that all three bars line up with the calendar.
Also test an empty schedule. The sample expects at least one task because it uses minimum and maximum dates. Add a clear validation message before those calculations if an empty schedule is possible.
Validate durations and names
A duration of zero may represent a milestone, but a negative duration is usually an error. Validate durations when tasks are created, rather than allowing invalid values to produce confusing bars.
The sample encodes task names before placing them in SVG text. Keep that protection if names can include characters such as & or angle brackets.
Choose the next feature based on a real need
Progress shading may help a team compare planned and completed work. A “today” marker may help with current projects. Zoom controls may be useful when schedules range from days to months.
Build one improvement at a time. For example, add a progress value to the task model, then render the completed portion as a second rectangle inside the planned bar.
Gantt Chart Project Planning with ONES.com
ONES.com brings project management and knowledge management together in one platform, powered by ONES Assistant. ONES Project handles project work, while ONES Wiki supports team knowledge; the products are sold separately.

A custom C# chart is useful when you need a specific visualization or want to embed a schedule in your own application. ONES Project can support the project workflows behind that visualization, including task coordination and reporting.
Core capabilities
- Disconnected project tracking → Jira-compatible workflows → Teams familiar with Jira can organize project work through comparable workflows in ONES Project.
- Limited visibility into progress → Built-in reporting → Project teams can review work status without constructing every report from scratch.
- Workflows that do not match team processes → Custom workflows and fields → Teams can shape how tasks move and which details they track.
- Sprint planning spread across separate processes → Sprint management → Agile teams can plan and track sprint work within their project workflow.
- Repeated manual task updates → Automation → Teams can automate suitable workflow actions and reduce routine coordination.
- Project and team knowledge kept apart → ONES.com’s PM and knowledge management platform → Teams can use ONES Project and ONES Wiki for their distinct needs within the broader platform.
- Deployment restrictions → Cloud, On-Premise, Private Cloud, or Air-gapped deployment → Organizations can select a deployment approach that fits their operating environment.
- Concern about losing capabilities when self-hosting → Feature parity between cloud and self-hosted versions → Teams can consider self-hosted deployment without giving up feature parity.
Application scenarios
A software team might use ONES Project to coordinate sprint tasks, while a custom C# chart displays a tailored release timeline in an internal application. The chart handles the specific visual requirement; the project workflow supports the team’s day-to-day coordination.
A company with on-premise or air-gapped requirements might use a deployment that suits its environment for project work. Separately, developers can create an SVG schedule for a specialized status view without treating that custom chart as a replacement for project management.
The practical distinction is simple: use C# when you need a purpose-built chart, and consider ONES Project when you need project workflows, reporting, and coordination. Choose the approach that matches the work you need to manage.
Common Challenges When Building a Gantt Chart in C#
Most problems come from unclear scheduling rules or missing validation, rather than from drawing the rectangles. Identify these issues early so they do not undermine the chart’s accuracy.
Bars start on the wrong date
Problem: A task appears shifted because the chart’s first date or day-width calculation is inconsistent.
Solution: Calculate every task’s offset from the same earliest date, then use one shared pixels-per-day value for bars and grid lines.
Task bars do not match working time
Problem: Calendar-day durations include weekends even though your team schedules only weekdays.
Solution: Define the duration rule before rendering. Add a working-day calculation if weekends or holidays should not count toward task length.
Labels become difficult to read
Problem: Long names overlap bars, or too many date labels crowd the timeline.
Solution: Reserve a consistent label column, shorten or wrap long names, and adjust tick frequency to the schedule’s time span.
Invalid task values break rendering
Problem: Empty schedules, negative durations, or unescaped characters produce exceptions or malformed SVG.
Solution: Validate task values before rendering and encode all text placed in SVG markup. Provide a clear response when no tasks are available.
Frequently Asked Questions
Can I create a Gantt chart in C# without a charting package?
Yes. You can generate SVG markup directly from C# using task dates and durations. The example in this guide draws task labels, weekly grid lines, and bars without a charting package. This approach works well when you need a small custom chart, though you will need to implement scheduling rules, styling, and interactions yourself.
Which C# technology should I use to display the chart?
SVG is a practical choice for a browser-based chart because browsers can render it directly. You can generate the markup in a console application, a web application, or another C# service. If you need drag-and-drop editing or advanced interactions, consider a UI framework or charting library that supports those features.
How can I show task dependencies?
Add dependency relationships to your task model, then draw connector lines between the corresponding bars. Before rendering, check that dependent tasks follow the required order. For example, if testing depends on development, the test start should not precede the development finish unless your schedule explicitly permits overlap.
How do I make task durations skip weekends?
Replace calendar-day arithmetic with a working-day calculation. Count eligible weekdays between the start and end dates, and exclude any holidays your project observes. Then calculate bar width from the number of working days. You may also need a non-linear timeline layout because ordinary calendar spacing includes weekend gaps.
Can I use ONES.com instead of building a custom chart?
ONES Project is a project management product with Jira-compatible workflows, built-in reporting, custom workflows and fields, sprint management, and automation. It can support project coordination, while a custom C# chart can handle a specialized visualization. Whether you need one or both depends on your team’s workflow and chart requirements.

Conclusion
You can create a useful Gantt chart in C# by modeling tasks clearly, converting dates into consistent coordinates, and rendering the schedule as SVG. Start with a few tasks and weekly markers, then verify date calculations and labels before adding advanced features.
When scheduling rules are unclear, bars can look convincing while showing the wrong plan. Decide how to treat working days, milestones, and dependencies, then test those cases deliberately.
With a reliable foundation, your chart can grow into a tailored project view. For the coordination behind that view, ONES Project offers project workflows and reporting, while your C# implementation can focus on the visualization your team needs.