This will be easier to demonstrate with both genders.  First, adjust your 
query to group by gender:

$query="SELECT sex_emp, COUNT( * ) AS cnt FROM empleado GROUP BY sex_emp";

and build your DataTable like this:

$table = array(
    'cols' => array(
        array('label' => 'Gender', 'type => 'string')
        array('label' => 'Count', 'type => 'number')
    ),
    'rows' => array()
);
while ($row = mysql_fetch_assoc($result)) {
    $table['rows'][] = array(
        'c' => array(
            array('v' => $row['sex_emp']),
            array('v' => $row['cnt'])
        )
    )
}

Then, you need to remove this line:

echo json_encode($table, JSON_NUMERIC_CHECK);

as it needs to output the data to the DataTable constructor.  Add in some 
chart code; as an example:

<script type="text/javascript" src="http://www.google.com/jsapi"; />
<script type="text/javascript">
function drawChart() {
    var data = new google.visualization.DataTable(<?php echo 
json_encode($data, JSON_NUMERIC_CHECK); ?>);
    
    var chart = new 
google.visualization.PieChart(document.querySelector('#chart'));
    chart.draw(data, {
        height: 400,
        width: 600
    });
}
google.load('visualization', '1', {packages:['corechart'], callback: 
drawChart});
</script>


and a <div> to hold the chart:

<div id="chart"></div>

The ID of the chart should match the ID used in the 
document.querySelector('#chart') call.

On Sunday, September 21, 2014 8:29:49 PM UTC-4, Andres Guilllermo Caviedes 
Campos wrote:
>
> I am trying to send the result of the query, but not how. I need to plot 
> the total number of employees by gender. Initially I have total men. As I 
> can make this graph a pie chart with Google Charts?  I could help?
>
> <html>
> <head>
> <title>Salario Aproximado</title>
> </head>
> <body>
>
> <?php
> $conexion=mysql_connect(" "," "," ") or
>   die("Problemas en la conexion");
> mysql_select_db(" ",$conexion) or
>   die("Problemas en la selección de la base de datos");
>
> $query="SELECT COUNT( * ) AS HOMBRES FROM empleado WHERE sex_emp = 
>  'HOMBRE'";
>
> $resultado=mysql_query($query);
>
> if ( !$result ) {
> // Nope
> $message  = 'Invalid query: ' . mysql_error() . "\n";
> $message .= 'Whole query: ' . $query;
> die( $message );
> }
>
> $table = array(
>     'cols' => array(
>         array('label' => 'HOMBRES', 'type => 'string')
>         array('label' => 'sex_emp', 'type => 'number')
>     ),
>     'rows' => array()
> );
> while ($row = mysql_fetch_assoc($result)) {
>     $table['rows'][] = array(
>         'c' => array(
>             array('v' => $row['HOMBRES']),
>             array('v' => $row['sex_emp'])
>         )
>     )
> }
> echo json_encode($table, JSON_NUMERIC_CHECK);
>
>  
> mysql_close($conexion);
> ?>
>
> </body>
> </html>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to