not displaying google charts in Laravel app

Posted 9 months ago by Amalmax

Hi, I am working with laravel 5.6 and I need displaying categoryname column values in google charts of vehicles table. My blade file is as following,


    <title>pie chart</title>
    <script src="{{ url('/js/jquery.js') }}"></script>
    <script type="text/javascript" src=""></script>


    <script type="text/javascript">
        var analytics = <?php echo $categoryname;  ?>
        google.charts.load('current', {'packages':['corechart']});


        function drawChart()
            var data = google.visulization.arrayToDataTable(analytics);

            var options = {
                title : 'Presentage of Categories'

            var chart = new google.visulization.PieChart(document.getElementById('pie_chart'));
<div class="container">
    <h3 align="center">Category Chart</h3>

    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-heading">Percentage of Categoryies</h3>
        <div class="panel-body">
            <div id="pie_chart" style="width:750px; height: 450px;">



and My ChartController is as


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;

class ChartController extends Controller
    function index()
        $data = DB::table('vehicles')
                DB::raw('categoryname as categoryname'),
                DB::raw('count(*)as number'))
        $array[] = ['Category','Number'];
        foreach($data as $key => $value)
            $array[++$key] = [$value->categoryname, $value->number];
        return view('reports.pie_chart')->with('categoryname', json_encode($array));

when I visit blade file I can see Only blade file and not displaying Google chart. How can fix this problem?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.