Skip to content

Instantly share code, notes, and snippets.

@LucianoCharlesdeSouza
Last active June 9, 2020 00:56
Show Gist options
  • Save LucianoCharlesdeSouza/7a51150ff6f5ee765b4082a1741b7ae9 to your computer and use it in GitHub Desktop.
Save LucianoCharlesdeSouza/7a51150ff6f5ee765b4082a1741b7ae9 to your computer and use it in GitHub Desktop.
@extends('admin.master.master')
@section('content')
<div class="box-canvas" style="width: 600px; height: 600px">
<canvas id="myChart"></canvas>
</div>
@endsection
@section('js')
<script src="{{ url('backend/assets/js/charts.js') }}"></script>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: {!! $labels !!},
datasets: [{
label: '# lista de usuários',
data: {!! $data !!},
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
@endsection
<?php
namespace LaraDev\Http\Controllers\Admin;
use Illuminate\Http\Request;
use LaraDev\Http\Controllers\Controller;
use LaraDev\User;
class ChartsController extends Controller
{
public function index()
{
$users = User::get(['id','name']);
$labels = collect($users)->pluck('name');
$data = collect($users)->pluck('id');
return view('admin.charts.index', compact('labels', 'data'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment