Gantt chart in html

Very Simple Responsive Gantt Chart With Pure HTML CSS

Welcome to a tutorial on how to create a Gantt Chart with pure HTML and CSS. Want to include a Gantt Chart in your project? Without using complicated and bloated libraries? Yes, it is possible with the modern CSS grid – Read on for an example!

ⓘ I have included a zip file with all the source code at the start of this tutorial, so you don’t have to copy-paste everything… Or if you just want to dive straight in.

TABLE OF CONTENTS

DOWNLOAD & DEMO

Firstly, here is the download link to the example code as promised.

QUICK NOTES

If you spot a bug, feel free to comment below. I try to answer short questions too, but it is one person versus the entire world… If you need answers urgently, please check out my list of websites to get help with programming.

EXAMPLE CODE DOWNLOAD

Click here to download all the example source code, I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

Читайте также:  Java измерить время выполнения метода

CSS GANTT CHART DEMO

PURE CSS GANTT CHART

All right, let us now get into the steps of building a simple Gantt chart using HTML and CSS grid.

PART 1) GANTT CHART HTML

  • Container for the Gantt Chart.
  • The “header cells”. Here, we have Monday to Sunday – A total of 7 cells.
  • TASK

    Self-explanatory, the individual tasks. Will explain more below.

PART 2) CONTAINER CSS

/* (A) GANTT CHART CONTAINER */ .gantt < /* (A1) GRID LAYOUT - 7 COLUMNS */ display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); /* (A2) "TIMELINE" */ background: repeating-linear-gradient( to right, #f2f2f2, #ddd 2px, #fff 2px, #fff 14.25% ); >
  • (A1) Captain Obvious to the rescue, set into the grid layout. Since it is Mon-Sun, there are 7 columns in total.
  • (A2) Using a linear-gradient “hack”, we draw the “timelines” in the background.

PART 3) HEADER CELLS

/* (B) CELLS */ /* (B1) SHARED CELLS */ .gantt div < padding: 10px; >/* (B2) HEADER CELLS */ .gantt .head

Don’t think these need explanation, just some cosmetics for the header cells.

PART 4) TASK CELLS

  • grid-row: N This task should be placed at this row in the grid.
  • grid-column: X / span Y This task will start at column X , span across Y cells.

That’s all for the tutorial, and here is a small section on some extras and links that may be useful to you.

IT WORKS, BUT…

Yes, we can totally build a Gantt Chart using pure HTML and CSS only. But as you can see, this is pretty much for simple charts only. It quickly turns into a real pain if you have multiple tasks and a long timeline – Having to manually calculate the rows/columns/span is going to be nasty.

Some form of “automation” with Javascript is still preferred for massive charts – Maybe I will build one in the future.

COMPATIBILITY CHECKS

This Gantt Chart will work on all modern “Grade A” browsers.

  • How To Create Grid In HTML CSS – Code Boxx
  • CSS Donut Chart – Code Boxx
  • CSS Pie Chart – Code Boxx
  • Bar Chart – Code Boxx
  • Example on CodePen – Pure CSS Gantt Chart

THE END

Thank you for reading, and we have come to the end. I hope that it has helped you to better understand, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!

Источник

How to Create a Simple Gantt Chart Using CSS Grid

Alfrick Opidi

Alfrick Opidi

How to Create a Simple Gantt Chart Using CSS Grid

A Gantt chart is a handy type of bar chart that is used in project management for showcasing a schedule of tasks. This chart visualizes project activities as cascading horizontal bars, with width depicting the project’s duration.

As a front-end web designer or developer, you can make use of Gantt charts to manage projects and enhance the productivity within your team.

In this article, I’m going to show you how to create a simple Gantt chart using the CSS Grid Layout system—no external libraries or other fluff, just pure CSS.

You can reference this tutorial to understand how to use the layout system for applying CSS rules.

The chart will show a typical software development life cycle process, from January to December.

Here is a screenshot of how the Gantt chart will look at the end of this tutorial:

s_71DD472E9787F22210482D610A0DD84B11827762D701C2FF3CA4E87715003165_1567325886724_gantt-chart

Step 1: Create a container div

Let’s start by creating a container div element for the Gantt Chart:

Let’s add some CSS styling to it:

Step 2: Create a chart div

Let’s create a div inside the overarching container and name it chart. This is where all the remaining actions are going to take place.

Let’s add some CSS styling to it:

Notice that I’ve set the display property of the class to grid. Consequently, all its direct children will automatically become grid items.

Step 3: Create the chart’s rows

Let’s start by creating the first row, which will be the heading of the Gantt chart.

 
JanuaryFebruaryspan>March AprilMayJuneJuly AugustSeptemberOctober NovemberDecember

Notice that I’ve provided 12 span elements that will transverse the entire row, showing the months of the project’s duration—from January to December.

.chart-period < color: #fff; background-color: #708090 !important; border-bottom: 2px solid #000; grid-template-columns: 50px repeat(12, 1fr); >.chart-period > span

Notice that I used the grid-template-columns property to specify the width and the number of columns in the grid layout.

Let’s see how it looks in a browser, so far:

s_71DD472E9787F22210482D610A0DD84B11827762D701C2FF3CA4E87715003165_1567023822884_gantt1

Next, let’s add lines that will run throughout the chart in a box-like style, which helps showcase the duration of each project.

I also used 12 span elements for creating the lines.

.chart-lines < position: absolute; height: 100%; width: 100%; background-color: transparent; grid-template-columns: 50px repeat(12, 1fr);>.chart-lines > span

Let’s see the output in a browser:

s_71DD472E9787F22210482D610A0DD84B11827762D701C2FF3CA4E87715003165_1567024250393_gantt2

Step 4: Add entry items

Finally, let’s add the items that illustrate a year-long process of creating some software.

For example, here is how I added the first entry item:

Let me describe what is happening in the code above:

  • First, the encompassing div element has a class of chart-row, which I illustrated earlier.
  • The div with a class of chart-row-item is used for numbering the entry items on the Gantt chart. Here is its CSS:
  • To show tasks on the Gantt chart, I created an unordered list and styled it to display a horizontal bar, with its length showing the duration of the task.

Here is the CSS styling for the chart-row-bars class:

Notice that I’ve used the grid-column property to specify the duration of the project.

For example, a property of grid-column: 3/9; like the “Development” entry, spans a task across the grid from March to August.

Here is how the first entry item looks in a browser:

s_71DD472E9787F22210482D610A0DD84B11827762D701C2FF3CA4E87715003165_1567024868326_gantt3

I added the other entries on the chart following the same process as the first entry. Ultimately, it resulted into a nice-looking Gantt chart, just like the image I showed earlier.

Wrapping up

That’s it! You can view the entire code for this tutorial on CodePen:

As you’ve seen, creating a Gantt chart using CSS Grid is not complicated. With this type of chart, you can manage your web development projects effectively and ensure that everyone is on track toward accomplishing the stipulated objectives.

Furthermore, Gantt charts can also be used in other industries to manage projects. For example, if you are selling composting toilets, you can use Gantt charts to showcase the number of sales made over a period of time.

Of course, I’ve just scratched the surface about the things you can achieve with Gantt charts.

There are several other tweaks you can make to Gantt charts to suit your specific requirements and project’s goals. For example, you can use them to show the relationship between various tasks and how the completion of one relies on another, show how resources can be allocated for the success of projects, and show clear project requirements that ensure everyone is on the same page.

Do you have any questions or comments?

Please get in touch via Twitter below and I’ll do my best to respond.

Источник

Оцените статью