Menu

PHPlot - pie chart

2015-11-06
2015-11-06
  • Yasmin Trindade da Silva

    May somebody help me?

    This file is receiving data perfectly, but I cannot plot a pie chart! :'(

    Thanks! ;)

    <head>
        <meta charset="utf-8">
        <title>Teste IC</title>
    </head>
    <body>
        <?php
            $stringHorarioCodificado = $_GET['stringHorarioCodificado']; //recebo os VALORES DO ARQUIVO .TXT
            $horario = urldecode($stringHorarioCodificado); //agora a ordem inversa, uso url decode para transforma no modo serializado
            $horario = stripslashes($horario); // retira as barras que vem depois de decodificado
            $horario = unserialize($horario);//e finalmente faço o unserialize, aqui ele volta a ser o array original.
    
            $stringTensaoCodificada = $_GET['stringTensaoCodificada']; //recebo os ÍNDICES
            $tensao = urldecode($stringTensaoCodificada); //agora a ordem inversa, uso url decode para transforma no modo serializado
            $tensao = stripslashes($tensao); // retira as barras que vem depois de decodificado
            $tensao = unserialize($tensao);
    
            $qtdeElementosHorario = count($horario);
            $qtdeElementosTensao = count($tensao);
    
            $auxiliar = 0;
    
            if($qtdeElementosHorario == $qtdeElementosTensao)
            {       
                while($auxiliar < $qtdeElementosHorario)
                {               
                    $matrizGrafico[$auxiliar]= array($tensao[$auxiliar], $horario[$auxiliar]);
                    //echo $tensao[$auxiliar] ." - ". $horario[$auxiliar]; recebeu CERTINHO
                    $auxiliar++;
                }
    
                require_once 'phplot.php';
                $plot = new PHPlot(300, 300);
                $plot->SetImageBorderType('plain');
                $plot->SetPlotType('pie');
                $plot->SetDataType('text-data-single');                 
                $plot->SetTitle('Título');
                $plot->SetDataValues($matrizGrafico);
                $plot->SetDataColors(array('red', 'green'));
                $plot->DrawGraph();                 
            }
            else
                echo "Ocorreu um erro no recebimento de dados.";
        ?>
    </body>
    
     

    Last edit: lbayuk 2015-11-06
  • lbayuk

    lbayuk - 2015-11-06

    Hello,

    (Note: I edited your post to put markers around the code so it will display properly on the forum.)

    First of all, remove everything (including spaces) before the PHP open tag <?php. Your script must output just an image file, nothing else. Especially nothing before the image. Then try again and let us know what happens.

    I did try the part of your script from after the 2 unserialize, with test arrays, and it did work.

    To aid future troubleshooting, are you able to look at your web server's error log? That is where PHP should report any errors, and it can be difficult to debug a script that should return image data without the error log. The alternative is to test the scripts with the PHP command-line (CLI), but that isn't always possible - for example when _GET is used.

     

Log in to post a comment.