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 in Interactive Dashboard Creation
Design ultra-high-performance and scalable dashboards
Training: Mastering Chart.js for Interactive Data Visualization on the Web
Understand the architecture and functioning of Chart.js
Training: Mastering Chart.js for Responsive and Interactive Data Visualization
Understand the functioning and architecture of Chart.js
Training: Mastering Interactive Data Visualization with Chart.js: Create Dynamic Dashboards
Understand the fundamental principles of data visualization on the web
Advanced TestRail API Training
Master the TestRail REST API for advanced automation
Advanced Testing Training with React Testing Library
Discover best practices for unit and integration tests on React
Ant Design Training
Easily install Ant Design in React
Chakra UI Training
Master advanced Chakra UI theming
Complete Training: Develop Your First Video Games with Cocos2d-x
Discover the architecture and potential of Cocos2d-x for video game development