Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
Premium Members Only
Join to unlock this tutorial and all of our courses.
Tutorial Premium Tutorial

Laravel and Chart.js: Simple Examples of Bar / Line / Pie Charts

October 27, 2022
6 min read

One of the most popular simple JavaScript libraries for charts is Chart.js. Let's see how to use it in Laravel, with three practical examples: bar, line, and pie charts.

In this tutorial, we will create three charts based on "users" DB table:

  1. Bar chart of registered users per day, in the last 30 days
  2. Same chart just in "line" mode instead of "bar"
  3. We will add a birth_date field and build a "pie" chart of birthdays per season: winter/spring/summer/fall.

But before building those charts, we need to have some kind of visual layout, and the data in the DB to show on the charts, right?


Prepare Laravel Application

For this tutorial, we will use our own Laravel Breeze Skeleton that gives us a simple design.

Laravel Breeze Skeleton

Next, the database schema. We'll add a birth_date field...

Premium Members Only

This advanced tutorial is available exclusively to Laravel Daily Premium members.

Premium membership includes:

Access to all premium tutorials
Video and Text Courses
Private Discord Channel

Comments & Discussion

DS
D.H SIMON ✓ Link copied!

Hello,

Can you please help how to use where_raw in your Laravel Daily Chart? This option can be used for all type of charts?

M
Modestas ✓ Link copied!

Hello, I'm not sure I understood your comment here. I'll try, but correct me if I'm wrong:

Using the whereRaw() is the same as selectRaw() or any other Raw function - you just need to write a mysql query manually. Keep in mind that this can be dangerous!

As for types of charts this works on - yes, it can be used on all charts. This is to retrieve the data from database and has nothing to do with the chart itself