Laravel Google Bar Chart
In Laravel, you can create a Google bar chart using the “laravel-gcharts” package.
- Install the “consoletvs/charts” package by running the command:
composer require consoletvs/charts
. - In your controller, use the package to generate the chart data. For example:
use ConsoleTVs\Charts\Facades\Charts;
class MyController extends Controller {
public function index() {
$chart = Charts::create('bar', 'google')
->title('My Chart')
->elementLabel('Total')
->values([5,10,20,8,12,3])
->dimensions(1000,500)
->responsive(true);
return view('chart', compact('chart'));
}
}
3. In your view, display the chart by calling the chart variable:
<div class="container">
{!! $chart->html() !!}
</div>
You can also customize the chart by passing options like title, labels, colors and more.
Note: Make sure you have enabled the Google Chart API and also have the API key, if you are using Google charts.