I want to make graphic with highcharts, I tried to conect it with my data base, but it doesn't work.. I don't know what could be wrong.. here is my code and the table from the data base:
<!DOCTYPE HTML>
<?php
include "conectar.php";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1,//null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
type: 'pie',
name: 'Consumidores',
data: [
<?php
$sql = "select * from consumidores";
$result = mysql_query($con,$sql);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>
['<?php echo $row["Nombre"] ?>', <?php echo $row["Edad"] ?>],
<?php } ?>
]
}]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
</body>
</html>
Here is the connection in another .php document:
<?php
$localhost = "localhost";
$my_user = "root";
$my_password = "propio";
$my_db = "mercado";
$conectado = false;
$con="";
$con = mysql_connect("$localhost","$my_user","$my_password","$my_db");
?>
and here is my table:
CREATE TABLE `consumidores` (
`ID_consumidor` INT(10) NOT NULL AUTO_INCREMENT,
`Nombre` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`Edad` INT(3) NULL DEFAULT NULL,
`Sexo` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`SalarioM` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`PreferenciaCompras` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`Direccion` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`Correo` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`Ciudad` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`EstadoCivil` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
`TarjetaCredito` VARCHAR(20) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
PRIMARY KEY (`ID_consumidor`)
)
COLLATE='latin1_spanish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=41;
OUTPUT FROM THE BROWSER SOURCE VIEW:
<!DOCTYPE HTML>
<?php
include "conectar.php";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1,//null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
type: 'pie',
name: 'Consumidores',
data: [
<?php
$sql = "select * from consumidores";
$result = mysql_query($con,$sql);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>
['<?php echo $row["Nombre"] ?>', <?php echo $row["Edad"] ?>],
<?php } ?>
]
}]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
</body>
</html>