ok guys need creating google bar chart php array. array
array (size=2) 0 => object(stdclass)[42] public 'nombre' => string 'anillo princess' (length=15) public 'total' => string '5' (length=1) 1 => object(stdclass)[43] public 'nombre' => string 'shake sabor vainilla' (length=20) public 'total' => string '1' (length=1)
and code generating chart
<script type="text/javascript"> google.load("visualization", "1.1", {packages:["bar"]}); google.setonloadcallback(drawstuff); function drawstuff() { var data = new google.visualization.arraytodatatable([ ['producto', 'cantidad'], ["anillo princess", 4], ["shake sabor vainilla", 1], ["colageno hidrolisado", 12], ["proteina lifeone", 10], ['otros', 3] ]); var options = { title: 'productos mas vendidos', width: 900, legend: { position: 'none' }, chart: { subtitle: 'cantidad vendidas' }, axes: { x: { 0: { side: 'top', label: 'productos'} // top x-axis. } }, bar: { groupwidth: "90%" } }; var chart = new google.charts.bar(document.getelementbyid('top_x_div')); // convert classic options material options. chart.draw(data, google.charts.bar.convertoptions(options)); }; </script>
how pass variable script generate chart values in array.
thans guys!
cheers.
heres attempt:
<? //original array $arr = [ ['nombre' => 'anillo princess', 'total' => '5'], ['nombre' => 'shake sabor vainilla', 'total' => '1'] ]; //loop , build output array $output = [["producto", "cantidad"]]; foreach($arr $row) { $output[] = [$row['nombre'], $row['total']]; } //echo result echo json_encode($output); ?>
this if want echo array straigth in code so:
var data = new google.visualization.arraytodatatable(<?=json_encode($output)?>);
but load data ajax request
Comments
Post a Comment