I hava table product
- id
- name
I would like to fetch data from database in a chart. And of course this breaks the chart and it doesn't work. Any suggestions would be greatly appreciated.
$products= Product::all();
return view('/')->with('products',$products) ;
Javascript :
function drawStacked() {
var data = google.visualization.arrayToDataTable([
@foreach($products as $product)],
[ '{{$product->name}}', '', '#000', {{$product->name}} ],
@endforeach
]);
var options = {
chartArea: {width: '50%'},
isStacked: true,
hAxis: {
title: 'All Product',
minValue: 0,
}
};
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}