Laravel 10 How To Integrate Line Chart Using HighChart Tutorial

Reading Time: 8 minutes

Inside this article we will see the concept i.e Laravel 10 How To Integrate Line Chart Using HighChart Tutorial. Article contains the classified information i.e Laravel 10 and Highcharts: Creating a responsive and interactive line chart.

Data visualization is an important aspect of web development, and line charts are one of the most popular ways to display data. Highcharts, a JavaScript charting library, provides a simple yet powerful way to create dynamic and interactive line charts on web pages.

In this article, we will explore how to integrate Highcharts with Laravel 10, a popular PHP framework, to create a dynamic line chart.

Read More: Creating a Dynamic Pie Chart with Highcharts in Laravel 10

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve


Assuming laravel already installed inside your system.

Create Database & Connect

To create a database, either we can create via Manual tool of PhpMyadmin or by means of a mysql command.

CREATE DATABASE laravel_app;

To connect database with application, Open .env file from application root. Search for DB_ and update your details.


Read More: How To Use Laravel 10 to Create a Dynamic Bar Chart

Create Model & Migration

Open project into terminal and run this command to create model and migration file.

$ php artisan make:model Student -m

It will create two files –

  • Model – Student.php inside /app/Models folder
  • Migration file – 2023_03_04_145928_create_students_table.php inside /database/migrations folder.

Open Migration file and write this complete code into it.


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('students', function (Blueprint $table) {
            $table->string("name", 120);

     * Reverse the migrations.
     * @return void
    public function down()

Open model file Student.php and write this complete code into it.


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Student extends Model
    use HasFactory;

    public $timestamps = false;

Run Migration

Back to terminal and run this command.

$ php artisan migrate

It will create students table inside database.


How To Create a Data Seeder in Laravel?

Create a seeder file to seed some dummy data for table.

Read More: How To Create Laravel 10 CRUD Application with Bootstrap

Run this command to terminal –

$ php artisan make:seeder StudentSeeder

It will create a file StudentSeeder.php at /database/seeders folder.

Open StudentSeeder.php and write this complete code into it.


namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

use Illuminate\Support\Facades\DB;

class StudentSeeder extends Seeder
     * Run the database seeds.
     * @return void
    public function run()
        $faker = \Faker\Factory::create();

        for ($loop = 0; $loop < 5; $loop++) {

                "name" => $faker->name(),
                "term1_marks" => $faker->numberBetween(45, 95),
                "term2_marks" => $faker->numberBetween(45, 95),
                "term3_marks" => $faker->numberBetween(45, 95),
                "term4_marks" => $faker->numberBetween(45, 95),
                "remarks" => $faker->randomElement(["Good", "Excellent", "Needs Improvement", "Better", "Poor"])

Run Seeder File

Run this command to terminal.

$ php artisan db:seed --class=StudentSeeder

It will create test data into database table.

Create Controller

Next, we need to create a controller file.

$ php artisan make:controller StudentController

It will create a file StudentController.php inside /app/Http/Controllers folder.

Open StudentController.php and write this complete code into it.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Student;

class StudentController extends Controller
    public function index()
        $students = Student::all();

        $dataPoints = [];

        foreach ($students as $student) {

            $dataPoints[] = array(
                "name" => $student['name'],
                "data" => [

        return view("line-chart", [
            "data" => json_encode($dataPoints),
            "terms" => json_encode(array(
                "Term 1",
                "Term 2",
                "Term 3",
                "Term 4",

Create a Blade Template File

Go to /resources/views folder and create a file with name line-chart.blade.php

Open line-chart.blade.php and write this complete code into it.

<!DOCTYPE html>
<html lang="en">

    <title>Laravel 10 How To Integrate Line Chart Using HighChart - ONLINE WEB TUTOR</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>


    <div class="container">
        <h4 style="text-align: center;">Laravel 10 How To Integrate Line Chart Using HighChart - Online Web Tutor</h4>
        <div class="panel panel-primary">
          <div class="panel-heading">Laravel 10 How To Integrate Line Chart Using HighChart</div>
          <div class="panel-body">
              <div id="line-chart"></div>
      <script src=""></script>
      <script src=""></script>
      <script src=""></script>
      <script src=""></script>
      <script src=""></script>
          Highcharts.chart('line-chart', {
              title: {
                  text: 'Students Term Wise Marks'
              yAxis: {
                  title: {
                      text: 'Number of Marks'
              xAxis: {
              categories: <?= $terms ?>
              legend: {
                  layout: 'vertical',
                  align: 'right',
                  verticalAlign: 'middle'
              series: <?= $data ?>,
              responsive: {
                  rules: [{
                      condition: {
                          maxWidth: 500
                      chartOptions: {
                          legend: {
                              layout: 'horizontal',
                              align: 'center',
                              verticalAlign: 'bottom'


Read More: How To Use DomPDF To Generate PDFs in Laravel 10

Add Route

Open web.php file from /routes folder. Add this route into it.


use App\Http\Controllers\StudentController;


Route::get('line-chart', [StudentController::class, 'index']);


Application Testing

Run this command into project terminal to start development server,

php artisan serve


Once we open this URL, Line Chart will be generated using Highchart plugin.


We hope this article helped you to learn about Laravel 10 How To Integrate Line Chart Using HighChart Tutorial Example in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.