Generate Pie Chart with PHP javascript

1

Good Morning Personal

I'm trying to add a pie chart as a result of a report.

    // PEGA A DATA DIGITADA VIA FORM $dateStart = $_POST['datainicial']; $dateEnd = $_POST['datafinal'];

// VARIÁVEL AUXILIAR PARA DATA $datainicial = $dateStart; $datafinal = $dateEnd;

// CRIA E EXIBE A ARRAY COM A RANGE DE DATA ESCOLHIDA VIA FORM $dateStart = implode('-', array_reverse(explode('/', substr($dateStart, 0, 10)))) . substr($dateStart, 10); $dateStart = new \DateTime($dateStart);

$dateEnd = implode('-', array_reverse(explode('/', substr($dateEnd, 0, 10)))) . substr($dateEnd, 10); $dateEnd = new \DateTime($dateEnd);

//IMPRIME INTERVALO $dateRange = array(); while ($dateStart <= $dateEnd) {
    $dateRange[] = $dateStart->format('d-m-Y');
    $dateStart = $dateStart->modify('+1day'); }

$dias = count($dateRange);

//echo "<pre>"; //print_r ($dateRange); //echo "</pre>";

//CONVERTE DATA FORMATO SQL $datainicialsql = date("Y-m-d", strtotime($datainicial)); $datafinalsql = date("Y-m-d", strtotime($datafinal));


// SELECIONA OS NUMERO TOTAL QUE FIZERAM BOOKINGS NO INTERVALO $result
= mysql_query("SELECT * FROM 'booking' LEFT JOIN customer ON booking.customer_id = customer.id WHERE (checkin >= '$datainicialsql' AND checkout <= '$datafinalsql')  ORDER BY customer.gender") or die(mysql_error());

$t=0;

//IMPRIME BOOKINGS while ($linha = mysql_fetch_array($result)) {

    //DADOS RELATÓRIO
    $vgender = $linha["gender"]; 
    //echo $vgender . "<br>";
    $t++;
     }

// SELECIONA OS NUMERO DE HOMENS QUE FIZERAM BOOKINGS NO INTERVALO $result = mysql_query("SELECT * FROM 'booking' LEFT JOIN customer ON booking.customer_id = customer.id WHERE (checkin >= '$datainicialsql' AND checkout <= '$datafinalsql')  AND customer.gender='Male' ORDER BY customer.gender") or die(mysql_error());

$m=0;

//IMPRIME BOOKINGS while ($linha = mysql_fetch_array($result)) {

    //DADOS RELATÓRIO
    $vgender = $linha["gender"]; 
    //echo $vgender . "<br>";
    $m++;
     }


// SELECIONA OS NUMERO DE MULHERES QUE FIZERAM BOOKINGS NO INTERVALO $result = mysql_query("SELECT * FROM 'booking' LEFT JOIN customer ON booking.customer_id = customer.id WHERE (checkin >= '$datainicialsql' AND checkout <= '$datafinalsql')  AND customer.gender='Female' ORDER BY customer.gender") or die(mysql_error());

$f=0;

//IMPRIME BOOKINGS while ($linha = mysql_fetch_array($result)) {

    //DADOS RELATÓRIO
    $vgender = $linha["gender"]; 
    //echo $vgender . "<br>";
    $f++;
     }

$tm = ($m / $t) * 100; $tf = ($f / $t) * 100;

echo "Homens : " . $m . " ( " . number_format($tm, 2, ',', '.') . " %" .  " ) " ."<br/>"; echo "Mulheres : " . $f . " ( " . number_format($tf, 2, ',', '.') . " %"  .  " ) " ."<br/>"; echo "Total : " . $t . " ( " . " 100%"  .  " ) " ."<br/>";

        return array();
    }

With this code I get through the counter the results I want.

TOTAL MEN: $ m TOTAL WOMEN: $ f TOTAL PEOPLE: $ t

Does anyone have any tips on how I can generate a graph with this data?

    
asked by anonymous 05.05.2015 / 03:17

1 answer

1

To generate the charts, simply use the Chart.js Library

07.05.2015 / 15:05