Step-by-step guide on creating a linear graph in CSS using a table

I am a newcomer to the world of CSS and I am looking to create a graph using CSS without the use of any libraries or frameworks. Can someone kindly assist me in drawing a linear graph using this HTML table? Appreciate any help in advance.

<html>
<head> TABLE TO GRAPH </head>
<body>
<table id ="graph" border="1">
<tr>
<th> WEEK </th>
<th> VISITORS </th>
</tr>
<tr>
<td> 1 </td>
<td> 20 </td>
</tr>
<tr>
<td> 2 </td>
<td> 40 </td>
</tr>
<tr>
<td> 3 </td>
<td> 60 </td>
</tr><tr>
<td> 4 </td>
<td> 80 </td>
</tr>
</table></body>
</html>

Answer №1

Creating a line graph using HTML and CSS can present some challenges, but generating a bar chart with these technologies is a more straightforward process.

See the Example Below:

.bar-chart {
display: table;
margin-top: 20px;
}

.row {
display: table-row;
}

.row div {
display: table-cell;
width: 60px;
height: 44px;
border-right: 2px solid rgb(255, 255, 255);
}

.row .axis-y {
width: 96px;
border-right: 1px solid #000;
vertical-align: top;
}

.axis-x div {
border-top: 1px solid #000;
}

.axis-x .axis-y {
border: none;
}

.axis-x div, .axis-y {
text-align: center;
font-weight: bold;
}

.row1 div:nth-of-type(n+2) {
background-color: rgb(255, 0, 0);
}

.row2 div:nth-of-type(n+3) {
background-color: rgb(255, 0, 0);
}

.row3 div:nth-of-type(n+4) {
background-color: rgb(255, 0, 0);
}

.row4 div:nth-of-type(n+5) {
background-color: rgb(255, 0, 0);
}
<div class="bar-chart">
<div class="row row4">
<div class="axis-y">80 Visitors</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<div class="row row3">
<div class="axis-y">60 Visitors</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<div class="row row2">
<div class="axis-y">40 Visitors</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<div class="row row1">
<div class="axis-y">20 Visitors</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<div class="row axis-x">
<div class="axis-y"></div>
<div>Week 1</div>
<div>Week 2</div>
<div>Week 3</div>
<div>Week 4</div>
</div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dividing the webpage background into separate sections to showcase a variety of colors, patterns, and more

I'm in the process of dividing the background on my website into distinct areas. My goal is to have the patterned area extend both horizontally and vertically on either side until it reaches the edge of the visible webpage. Figuring out how to achiev ...

Troubleshooting Layout Problems in HTML and CSS

My goal is to build a straightforward webpage template with 3 distinct sections: a header with two columns, a main body, and a footer. Here's the layout I've been working on: <div id="wrapper"> <div id="header"> <heade ...

What is the best way to keep a bootstrap navbar fixed at the top when scrolling? (It's a bit tricky)

Check out this image of my website header. HERE Is there a way to achieve a smooth scrolling effect for the blue navbar as I scroll down the page? (Specifically just the navbar, excluding the logo and social media elements). Using position:fixed; does ...

Dynamic sliding box jumps instead of simply fading in/out

My app features both a navigation bar and a sub-navigation bar. Within the sub-navigation bar, users can click on a button that triggers the appearance of another sub-bar while hiding the original one. The new sub-bar should smoothly slide out from behind ...

Adding margin padding to a Material UI Navbar: Step-by-step guide

Hey there, I've added buttons to my Navbar from Mui. However, I'm running into an issue where the margin and padding won't change no matter what I do. I'm trying to create some space between them. Please see the code below: import { use ...

Unable to assign a default value to an Angular input field

My web page utilizes an Angular form to display user data fetched from a MongoDB database. The information includes the user's name, phone number, email, etc. I want the default value of the input field to be set as the placeholder text, allowing user ...

Horizontal expanding and collapsing navigation menu

Is there a way to modify the expand menu bar so it expands from left to right or right to left, instead of top down? Any assistance would be greatly appreciated. Existing Expand Menu Bar <HTML> <HEAD> <META http-equiv="Content-Type" c ...

Struggling to make css selector acknowledge the margins on the right and left

I am trying to style two inner divs within a containing div by floating the first one to the left and the second one to the right. Additionally, I want to add a margin of 15px on the left for the first div and on the right for the second div. The challenge ...

Creating an HTML Canvas effect where images are placed onto another image

Looking to create a similar effect as seen on this website () On this site, users can upload their images (4000 * 400) and have the option to add Mickey Mouse ears over their image before saving it. The Mickey Mouse ear is resizable from all four sides f ...

Getting the result from HTML5 FileReader: How does it work?

Dealing with the asynchronous nature of JS FileReader can be challenging. I need to retrieve the result after reading a file and work with that data, but I don't know when the result will be ready. How can I handle this situation effectively? $(docum ...

What steps can be taken to override the property overflow:hidden specifically for a custom tooltip design

I am facing a challenge with overriding the property overflow:hidden in the parent td element. https://i.stack.imgur.com/HKcvn.png This issue is related to my tooltip, which ideally should be displayed beneath the td element: Code snippet for the toolti ...

Generating a dataframe with cells that have a combination of regular and italicized text using the sjPlot package functions

I've been trying to set up a basic data table where the genus name in the "Coral_taxon" column is italicized, but the "spp." part following it remains lowercase. I thought of using the expression() function for each row in "Coral_taxon," but so far, I ...

Tips for filling the offset space with a column

Having a bit of trouble phrasing my question, but here's the issue I'm facing: Currently, I need to develop two different views, the first being the mobile view However, I'm experiencing some difficulties with the second view, which can be ...

What is the best way to delete the pipe separator from the initial item in a list on the line?

I have a list of items separated by pipes that spans multiple lines. I am looking to use jQuery to remove the pipe separator for the first item on each line. Example: Red | Green | Blue Purple | Black | White Violet | Yellow | Magenta Here is the code ...

Concealing div containers and eliminating gaps

Looking for a way to filter div boxes using navigation? Check this out: <ul> <li><a href="javascript:void(0);" data-target="apples">Appels</a></li> <li><a href="javascript:void(0);" data-target="bananas">Ban ...

How to position text in the center of a video using CSS

My attempt to center the name of my blog on top of a video background was not successful, even though I tried positioning it absolutely with 50% from the top. Can someone assist me in vertically and horizontally centering the text over the video? Here is ...

The color attribute in a Div container remains the same even when hovering over it

Hello everyone, I am new to stack overflow so please bear with me. I am currently working on this small webpage for my IT course and I have encountered a significant issue. .float1 { float:right; background-color:#A3635C; margin-top: 150px; ...

I must design a unique layout for my website

I am creating a webpage with various shapes and elements. However, I am facing a challenge with creating a shape that is commonly used. In platforms like Khan Academy, there is simulated programming where shapes can be easily created with a simple command ...

Exploring how to set dropdown menu width for Angular2 mat-select options

Currently, I am using the angular2 mat-select control and facing an issue with the width and position of its dropdown list menu. By default, it is wider and overflows the element on both sides by a few pixels. I have not found any option for adjusting the ...

Unable to scroll down an overlay window using Selenium with Python

When using Quora, I am trying to scroll to the bottom of the window that appears when I click on the "View upvoters" button in order to access all the names of those who have upvoted. However, the code for scrolling down a standard browser window doesn&apo ...