Laravel PHP Google 3D pie chart add rows dynamically using visualization table Example

Laravel PHP Google 3D pie chart add rows dynamically using visualization table Example

Google 3D pie charts add rows dynamically using visualization table in PHP Laravel Framework

In this tutorial, i will tell you following thing that i have used in google pie charts :

  • Use of Google Pie Chart
  • Pass Eloquent data from Controller to view and how can i get php value in script.
  • How to add dynamically rows with two columns to a Google Pie Charts.
  • About Google Visualization Data Table
  • Use of event addListener in Google Pie Chart

Charts are mostly used to generate report to see the summary of details.

Here i have a user table with additional column source where user is registered from different source as facebook and google.

You can see some steps from here to Install Laravel, Create Table and Model

I display the total registered user of each source in google piechart.

I assume that you have install laravel in your system if don't have then install laravel first

Route and Controller

Here i define route google-piechart with get method that call ChartController with pieChart method.

routes.php

  1. Route::get('google-piechart',array('as'=>'chart.piechart','uses'=>'ChartController@pieChart'));
ChartController.php

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\User;
  6. class ChartController extends Controller {
  7. public function pieChart(){
  8.         $social_users=User::selectRaw('count(source) as count,source')->groupBy('source')->get();
  9.     $user=array();
  10.     foreach ($social_users as $result) {
  11.         $user[$result->source]=(int)$result->count;
  12.     }
  13. return view('piechart',compact('user'));
  14. }
  15.     
  16. }

You will notice that here i use selectRaw method that are used to write raw query while working with Laravel Eloquent.

View File

Now create piechart.blade.php

resources/views/piechart.blade.php

  1. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  2. <script type="text/javascript">
  3. google.charts.load("current", {packages:["corechart"]});
  4. google.charts.setOnLoadCallback(drawChart);
  5. function drawChart() {
  6. var record={!! json_encode($user) !!};
  7. console.log(record);
  8. // Create our data table.
  9. var data = new google.visualization.DataTable();
  10. data.addColumn('string', 'Source');
  11. data.addColumn('number', 'Total_Signup');
  12. for(var k in record){
  13. var v = record[k];
  14. data.addRow([k,v]);
  15. console.log(v);
  16. }
  17. var options = {
  18. title: 'My Daily Activities',
  19. is3D: true,
  20. };
  21. var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
  22. chart.draw(data, options);
  23. }
  24. </script>
  25. <div id="piechart_3d" style="width: 900px; height: 500px;"></div>

Now you can use this demo code in your application for Google pie chart.

You can customize option value as per need and add dynamic title and set click event to see full report too.

To use event addListener follow the syntax :

  1. google.visualization.events.addListener(chart, 'select', function() {
  2.     var row = chart.getSelection()[0].row;
  3.     var selected_data=data.getValue(row, 0);
  4.     var url = "demo.expertphp/google-pie-chart?data="+selected_data ;
  5.      window.open(url, '_blank');
  6. });

Click here to see the demo how it is working

Phone: (+91) 8800417876
Noida, 201301
okey metin2 pvp serverler metin2 pvp
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat

viagra fiyatı

viagra 100 mg fiyat

viagra sipariş

orjinal viagra

viagra satın al

izmir escort
ataşehir escort
kocaeli escort izmit escort bayan gebze escort izmit sınırsız escort escort bursa tuzla escort aydınlı escort orhanlı escort bursa escort escort bayan istanbul escort istanbul sınırsız escort istanbul bayan escort izmit escort izmit escort kocaeli escort sisli escort mecidiyekoy escort bursa escort bayan bursa görükle escort maltepe escort goztepe escort yakacik-yeni-escort bursa sınırsız escort sisli escort bayan taksim escort bursa escort porno izle sikiş izle atasehir escort antalya escort
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort
bedava bahis