HomeLaravel

laravel 5 : Google Charts, Simple Geo Chart using Lavacharts in Laravel 5.3

Laravel 5.3 tutorial for beginners - Google Charts, Simple Geo Chart using Lavacharts in Laravel 5.3, Lavacharts is a wrapper for Google's powerful Javascript Chart API, More detail https://github.com/kevinkhill/lavacharts or http://lavacharts.com/

Laravel 5 Tutorial : Image Upload and Resize using Image Intervention with Validation in Laravel 5.3
Laravel 5 Tutorial : How to Export to PDF using Dompdf Library with Example
laravel 5 Tutorial : Laravel 5.3 Multiple File Upload & Save Into Database
Laravel 5.3 Tutorial - Lavacharts is a wrapper for Google's powerful Javascript Chart API,
 More detail https://github.com/kevinkhill/lavacharts or http://lavacharts.com/.

How to create simple Geo Chart using Lavacharts in Laravel 5.3?
First, you must have a database, i'm using MySQL database, just create "lavachart" database using MySQL.
Simple Geo Chart using Lavacharts in Laravel 5.3

Create Simple Geo Chart Project

cd c:\server\htdocs
....
composer create-project --prefer-dist laravel/laravel lavacharts

Create Connection to Database

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lavacharts
DB_USERNAME=root
DB_PASSWORD=yourpassword

Create Table and Migrations

php artisan make:migration create_table_charts_table

in Migration files, add this function to create charts table

<?php

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

class CreateChartsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
      Schema::create('charts', function (Blueprint $table) {
      $table->increments('id');
      $table->string('country');
      $table->integer('users');
      $table->timestamps();
      });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('charts');
    }
}

Create Models

php artisan make:model Charts

Add this function to "Charts" model

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Charts extends Model
{
  protected $table ='charts';
  public $fillable = ['country','users'];
}

Next, we will add Lavacharts into project,

Installing Lavacharts

First, copy this line into your project's composer.json file, in the "require": {} section,

"khill/lavacharts" : "3.0.*"

Next, run composer to download and install.

composer update

Register the service provider

Register the service provider by adding this line to the providers array in config/app.php

Khill\Lavacharts\Laravel\LavachartsServiceProvider::class,

Create Controller

Create new controller following this command :

php artisan make:controller ChartsController

Next, add this function into our controller (ChartsController.php)

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Charts;
use Khill\Lavacharts\Lavacharts;
class ChartsController extends Controller
{
    public function chart(){
      $lava = new Lavacharts;
      $popularity = $lava->DataTable();
      $data=Charts::select("country as 0","users as 1")->get()->toArray();
      $popularity->addStringColumn('Country')
                  ->addNumberColumn('Users')
                  ->addRows($data);
      $lava->GeoChart('Popularity',$popularity);
      return view('charts.chart',['lava' => $lava]);
    }
}

Routes

create new routes
Route::get('charts/chart', 'ChartsController@chart');

Create Views
First, we will create new folder named with "charts" under resources folders, resources\views\charts.

Next, create new file (chart.blade.php) under charts folder resources\views\charts\chart.blade.php

Chart.blade.php

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Simple Geo Map - Chart Map</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container">
      <div class="row">
        <div class="col-md-12">
          <h1>Geo Map using LavaCharts</h1>
          <div id="pop-div" style="width:800px;border:1px solid orange"></div>
            <?= $lava->render('GeoChart', 'Popularity', 'pop-div') ?>
        </div>
      </div>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  </body>
</html>

Try and Error

Finally, try to open your project using Google Chrome Browser :

http://localhost:8080/charts/chart

[UPDATE] VIDEO TUTORIAL USING GOOGLE CHARTS FULL CUSTOMIZE


Video tutorial Simple Geo Chart using Lavacharts in Laravel 5.3



Download full source code Google Charts, Simple Geo Chart using Lavacharts in Laravel 5.3 >> https://goo.gl/NzoiDL

See you next lessons..

Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


COMMENTS

DISQUS
Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,89,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,6,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: laravel 5 : Google Charts, Simple Geo Chart using Lavacharts in Laravel 5.3
laravel 5 : Google Charts, Simple Geo Chart using Lavacharts in Laravel 5.3
Laravel 5.3 tutorial for beginners - Google Charts, Simple Geo Chart using Lavacharts in Laravel 5.3, Lavacharts is a wrapper for Google's powerful Javascript Chart API, More detail https://github.com/kevinkhill/lavacharts or http://lavacharts.com/
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnnlQHARbpn5d8qNzOZZq-wepu9EZMC5Yl_zVWM5hHJ5QPHykTGTYtuj7Mn5EBmJBh5fEgF1JKOVf5A5sRETTuTzgbFtU01hoN15IgCNvJbOTCWO7_g3QGSRZmbhAvcMmLABRtae2elxY/s320/geo-lavachart-laravel5.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnnlQHARbpn5d8qNzOZZq-wepu9EZMC5Yl_zVWM5hHJ5QPHykTGTYtuj7Mn5EBmJBh5fEgF1JKOVf5A5sRETTuTzgbFtU01hoN15IgCNvJbOTCWO7_g3QGSRZmbhAvcMmLABRtae2elxY/s72-c/geo-lavachart-laravel5.png
KODE AJAIB
https://scqq.blogspot.com/2016/10/laravel-5-google-charts-simple-geo.html
https://scqq.blogspot.com/
https://scqq.blogspot.com/
https://scqq.blogspot.com/2016/10/laravel-5-google-charts-simple-geo.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy