if (isset ($_POST['tabella_completa']))
{
$query="SELECT * FROM tabella ORDER BY id";
$risultato = @mysql_query($query);
$numcampi = @mysql_num_fields($risultato);
$flag = true;
$table = array();
$arrayprincipale = array();
$comodo = array();
for ($i=0 ; $i<$numcampi ; $i++)
{
$comodo = array('label' => mysql_field_name($risultato,$i), 'type' => 'string');
array_push($arrayprincipale, $comodo);
}
$table['cols'] = $arrayprincipale;
$rows = array();
if ($risultato) {
while($r = mysql_fetch_assoc($risultato)) {
$temp = array();
for ($i=0 ; $i<$numcampi ; $i++)
{
$temp[] = array('v' => (string) $r[mysql_field_name($risultato,$i)]);
}
$rows[] = array('c' => $temp);
}
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
}
<script type="text/javascript" src="../smartstructure2/jsapi"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1.1", {packages:["line"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var options = {
chart: {
title: 'Monitoraggio',
subtitle: 'Acquisizione dati'},
series: {
// DEFINISCO GLI ASSI A CUI DARE IL NOME
0: { axis: 'AsseY'}
},
axes: {
// AGGIUNGO IL NOME ALL'ASSE
y: {
AsseY: {label: 'Asse Y'}
}
}
};
var chart = new google.charts.Line(document.getElementById('linechart_material'));
chart.draw(data, options);
}
</script>
<div id="linechart_material" style="width: 850px; height: 350px; margin-left:auto; margin-right:auto">
<div id="TABELLA">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1.1", {packages:["table"]});
google.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '700px', height: '100%'});
}
</script>
<div id="table_div"></div>