How to use HTML for Data Visualization ?
Last Updated :
27 Sep, 2023
In this article, we are going to discuss Data Visualization techniques that can be employed to make the communication of data easier and more effective. Data Visualization in HTML involves presenting data in graphical or visual formats using HTML, CSS, and SVG. It enhances data comprehension and insights through charts, graphs, and other visual representations.
There are several methods that can be used to visualization of data in HTML.
- Simple Data Visualization using <table>
- Data Visualization using SVGs
Approach 1: Simple Data Visualization using <table>
HTML tables are a basic data visualization approach where data is presented in tabular form, using rows and columns to organize and display information.
Syntax:
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
</tr>
<tr>
<td>Data cell 1</td>
<td>Data cell 2</td>
</tr>
</table>
Example: Here is an example of the above syntax-
HTML
<!DOCTYPE html>
<html>
<head>
<title>Simple Table</title>
</head>
<body>
<table border="black">
<thead>
<tr>
<th>Heading 1</th>
<th> Heading 2</th>
</tr>
</thead>
<tbody>
<tr>
<td> Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 5</td>
<td>Data 6</td>
</tr>
</tbody>
</table>
</body>
</html>
Output:
Output of the TableApproach 2: Data Visualization using SVGs
The process of employing Scalable Vector Graphics (SVGs) for data visualization entails building unique, interactive visualizations that can be manipulated with JavaScript to produce dynamic charts, graphs, and shapes.
Syntax:
<svg width="width" height="height">
<!-- Bar 1 -->
<rect x="val1" y="val2" width="val3" height="val4" fill="val5" />
<!-- Bar 2 -->
<rect x="val5" y="val7" width="val8" height="val9" fill="val10" />
<!-- Bar 3 -->
<rect x="val11" y="val12" width="val13" height="val14" fill="val15" />
</svg>
Example: In this example, we create a basic SVG bar chart with three data points represented by green bars, along with axis lines and labels.
HTML
<!DOCTYPE html>
<html>
<head>
<title>SVG Data Visualization - Bar Chart</title>
</head>
<body>
<svg width="400" height="300">
<!-- Data points for the bar chart -->
<rect x="70" y="100" width="50"
height="120" fill="green" />
<rect x="170" y="100" width="50"
height="120" fill="green" />
<rect x="270" y="100" width="50"
height="120" fill="green" />
<!-- Axis lines and labels -->
<line x1="30" y1="10" x2="30"
y2="220" stroke="black" />
<line x1="30" y1="220" x2="380"
y2="220" stroke="black" />
<text x="10" y="15" font-size="12"
fill="black">
200
</text>
<text x="10" y="85"
font-size="12"
fill="black">
150
</text>
<text x="10" y="155"
font-size="12"
fill="black">
100
</text>
<text x="10" y="225"
font-size="12"
fill="black">
50
</text>
<text x="80" y="240"
font-size="12"
fill="black">
Data 1
</text>
<text x="180" y="240"
font-size="12"
fill="black">
Data 2
</text>
<text x="280" y="240"
font-size="12"
fill="black">
Data 3
</text>
</svg>
</body>
</html>
Output:
Output
Similar Reads
How to Build a Website using HTML? Building a website using HTML (Hypertext Markup Language) is the foundation of web development. HTML allows you to structure content, define headings, paragraphs, lists, and links, and create visually appealing web pages.In this article, we'll learn the fundamentals of How to build a Website using H
5 min read
How to include SVG code inside HTML file ? SVG stands for Scalable Vector Graphics. It is an XML-based format used to describe vector graphics. SVG is widely supported in modern web browsers, including Google Chrome, Firefox, Opera, and others, which can render SVG images seamlessly. Designers frequently use the SVG format for creating illus
1 min read
How to Create an Image Map in HTML ? An image map is a graphical representation that allows you to define clickable areas (or "hotspots") within an image. Each hotspot can be associated with a hyperlink, making different parts of the image interactive. Image maps are commonly used for navigation menus, interactive diagrams, and geograp
2 min read
How to Create Table in HTML? HTML tables are used for organizing and displaying data in a structured format on web pages. Tables are commonly used for product information, presenting data analytics, or designing a pricing comparison chart. Elements of HTML TableTable ElementsDescription<table>The <table> element def
3 min read
How to include HTML code snippets in HTML ? In this article, we will learn how to include HTML snippets in HTML code. We will include the HTML code snippet of "gfg.html" into "index.html". To achieve this task, we are going to write a JavaScript function in "index.html" which traverses the collection of all HTML elements in "gfg.html" and sea
3 min read
How to use PHP in HTML ? In this article, we will use PHP in HTML. There are various methods to integrate PHP and HTML, some of them are discussed below. You can add PHP tags to your HTML Page. You simply need to enclose the PHP code with the PHP starts tag <?php and the PHP end tag ?>. The code wrapped between these
2 min read
How to write sample output of a computer program using HTML? To write the sample output of a computer program using HTML5, utilize the <samp> tag. This tag is a phrase tag specifically designed to represent sample output from a computer program, ensuring the text is appropriately styled and semantically meaningful. Syntax:<samp> Contents... </s
1 min read
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
Interesting Facts about HTML Here are some interesting facts about HTML (Hypertext Markup Language):HTML is Not a Programming Language: Itâs a markup language designed to structure and present content on the web.HTML is Everywhere: It's not just for web browsers! Many applications, email clients, and even mobile apps use HTML f
2 min read