It is currently Tue Dec 12, 2017 5:44 pm Advanced search

how show array in pie-basic with MySQL?

Technical support, bug reports and more.

how show array in pie-basic with MySQL?

Postby Fernandoomer » Sat Aug 12, 2017 7:40 pm

Hello everyone, i'm here ´cause I was really try to show data of a table of my db in a pie-basic chart... but a can't do this sucessfull. I'm really tired and Unmotivated. Please need your help for this
(sorry for my english hehehe i'm spanish)

I think the problem is this, when i try to show the query:

I tested the query and it's ok.

series: [{
name: 'bancos',
type: 'pie',
colorByPoint: true,
data:
[

<?

$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "pruebabci");

$result = mysqli_query($link, "SELECT tipo, count(*) FROM instituciones group by tipo");

while ($extraido= mysqli_fetch_array($result))
{

$inst = echo utf8_encode($extraido[00]);
$tot = $extraido[01];

?>

[ '<?php echo $inst ?>' , <?php echo $tot; ?> ], /// <--- here i don't know how show de information in the chart!!!!!!!!!!!!!



<?

}

mysqli_free_result($result);
mysqli_close($link);

?>

THANKS!!!
Fernandoomer
 
Posts: 2
Joined: Sat Aug 12, 2017 4:41 pm

Re: how show array in pie-basic with MySQL?

Postby Fernandoomer » Sat Aug 12, 2017 7:43 pm

Here the complete code:

<!-- ..........................Codigo Java Highchart.......................... -->
<!-- ..........................Codigo Java Highchart.......................... -->

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Stats F.Opazo BCI</title>

<style type="text/css">
#container {
font-family: Georgia, Times New Roman, Times, serif;
}
#container {
font-family: Arial, Helvetica, sans-serif;
}
#container {
color: #333;
}
.A {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #333;
}
</style>
</head>
<body>
<p>
<script
src="http://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<script src="code/highcharts.js"></script>
<script src="code/modules/exporting.js"></script></p>
<table width="100%" border="0">
<tr>
<th width="238" scope="col"><div align="center"><img src="untitled.png" width="238" height="83"></div></th>
<th width="533" class="A" scope="col"><div align="center">Estadísticas Entidades Financieras De Chile - Fernando Opazo Gutiérrez</div></th>
<th width="221" scope="col"><div align="center"><img src="Statslogo.png" width="136" height="127"></div></th>
</tr>
</table>
<table width="100%" border="0">
<tr>
<th height="39" bgcolor="#FFFF00" scope="col"><div align="justify"></div></th>
<th bgcolor="#0033FF" scope="col"><div align="justify"></div></th>
<th bgcolor="#006600" scope="col"><div align="justify"></div></th>
<th bgcolor="#999999" scope="col"><div align="justify"></div></th>
<th bgcolor="#FF0000" scope="col"><div align="justify"></div></th>
</tr>
</table>
<p>&nbsp;</p>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>



<script type="text/javascript">

Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Cantidad de instituciones por tipo al 2017'
},
tooltip: {
pointFormat: '{series.name}: <b></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'
}
}
}
},

//------------------acá se muestran los datos del gráfico--------------------------//
//------------------acá se muestran los datos del gráfico--------------------------//

series: [{
name: 'bancos',
type: 'pie',
colorByPoint: true,
data:
[

<?

$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "pruebabci");

$result = mysqli_query($link, "SELECT tipo, count(*) FROM instituciones group by tipo");

while ($extraido= mysqli_fetch_array($result))
{

$inst = echo utf8_encode($extraido[00]);
$tot = $extraido[01];

?>

[ '<?php echo $inst ?>' , <?php echo $tot; ?> ],




<?

}

mysqli_free_result($result);
mysqli_close($link);

?>




]
}]

//-------------------------------------------------------------------------//
//-------------------------------------------------------------------------//

// series: [{
// name: 'bancos',
// colorByPoint: true,
// data: [

// {name: 'Microsoft Internet Explorer', y: 27},
// {name: 'niño', y: 24.03, sliced: true, selected: true},
// {name: 'niña', y: 10.38},
// {name: 'Safari', y: 4.77},
// {name: 'Opera', y: 0.91},
// {name: 'Proprietary or Undetectable', y: 0.2}
// ]

// }]



//-------------------------------------------------------------------------//
//-------------------------------------------------------------------------//

});
</script>
</body>
</html>
Fernandoomer
 
Posts: 2
Joined: Sat Aug 12, 2017 4:41 pm

Re: how show array in pie-basic with MySQL?

Postby seba » Tue Aug 15, 2017 12:56 pm

I think that better is separate PHP code and Javascript. You can communicate backend (PHP) with front by JSON.

To do that create an array of data in PHP and return it by json_encode() method.

In javascript use ajax (i.e $.getJSON()) and load data from url and init a chart.
Sebastian Bochan
Highcharts Developer
seba
 
Posts: 4410
Joined: Tue Jul 31, 2012 4:26 pm


Return to Highcharts Usage

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests