
Problema al usar google chart
Publicado por José Vicente (3 intervenciones) el 05/11/2022 09:17:04
Hola, estoy intentando hacer una página web con php en la que intento mostrar los datos de una tabla postgres en un gráfico google chart pero no consigo que me muestre nada. Mi código es:
¿Podeis echarme un cable? Gracias.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<?php
$db_conexion = pg_connect("host=localhost dbname=base_datos user=usuario password=contraseña");
?>
<html>
<head>
<meta charset="UTF-8">
<title> GRÁFICA WEB </title>
<script src="https://www.google.com/jsapi"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['fecha','sistolica','diastolica','pulsaciones','saturacion'],
<?php
$query = "SELECT * from VALORES";
$exec = Pg_query($db_conexiononexion,$query);
while($row = pg_fetch_array($exec))
{
echo "['".$row['fecha']."',".$row['sistolica']
."',".$row['diastolica']."',"
.$row['pulsaciones']."',".$row['saturacion']."],";
}
?>
]);
var options = {
title: 'VALORES OBTENIDOS',
hAxis: {title: 'FECHAS', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<body>
<div id="chart_div" style="width: 100%; height: 500px;"></div>
</body>
</html>
Valora esta pregunta


0