Introduction
Chart.js is a lightweight, powerful open-source JavaScript library for creating interactive charts directly in the browser. In 2026, it's still the #1 choice for frontend developers thanks to its simplicity, performance (native canvas rendering), and support for over 8 chart types: lines, bars, pie, radar, and more. Unlike low-level D3.js, Chart.js is plug-and-play: think of it as Lego for data, where you assemble datasets and options in just a few lines.
Why use it? For analytics dashboards, financial reports, or scientific visualizations without a heavy backend. This beginner tutorial takes you from the basics (a simple line chart) to advanced options (animations, responsive tooltips). By the end, you'll know how to build a complete dashboard. Estimated time: 15 minutes for your first working chart. All code is copy-pasteable and live-testable on CodePen.
Prerequisites
- Basic knowledge of HTML, CSS, and JavaScript (beginner level).
- A code editor like VS Code.
- A modern browser (Chrome, Firefox).
- No npm installation needed: we use the CDN for instant setup.
Basic HTML Structure with CDN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>First Chart.js Example</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.js"></script>
</head>
<body>
<div style="width: 80%; margin: 0 auto;">
<canvas id="myChart" width="400" height="200"></canvas>
</div>
<script>
// Chart code will be added in the following steps
</script>
</body>
</html>This HTML file loads Chart.js via CDN (stable 4.4.3 version in 2026). The canvas is the key element: it's the drawing area. Inline styles for quick centering; don't forget the viewport meta tag for mobile responsiveness.
First Chart: Line Chart
Let's start with a simple line chart, perfect for showing trends over time (e.g., monthly sales). Chart.js uses a config object with type, data (labels + datasets), and options. Copy the script into the
Recommended Learni Training Courses
Go further with our Learni training courses dedicated to professionals.
Training Chart.js - Create Professional Interactive Charts
Master the fundamentals of Chart.js for professional visualizations
Training Chart.js - Creating High-Performance Interactive Charts
Master the fundamentals of Chart.js for professional visualizations
Training Chart.js - Creating Interactive Web Graphics
Master the fundamentals of Chart.js for professional visualizations
Training Chart.js 2026 - Advanced Interactive Data Visualization
Master advanced Chart.js 2026 configurations for professional visualizations
Training: Master Chart.js for Interactive Data Visualization on the Web
Understand the architecture and functioning of Chart.js
Training: Master Interactive Data Visualization with Chart.js: Create Dynamic Dashboards
Understand the fundamental principles of data visualization on the web
Training: Mastering Chart.js for Responsive and Interactive Data Visualization
Understand the functioning and architecture of Chart.js
Advanced Algolia Training - Boost Your Ultra-Fast Searches
Configure complex indexing pipelines with Rules and Synonyms.
Advanced Algolia Training - Optimize Ultra-Fast Searches
Configure complex indexing pipelines with advanced rules