首页  >  问答  >  正文

图形无法显示在PHPLOT上

<p>如果可能的话,我想在PHPLOT上寻求帮助。图表在使用虚拟数据时正常显示,但是当我调用$words数组时,图表不显示。</p> <p>图表代码:</p> <pre class="brush:php;toolbar:false;"><?php include_once ("class/ProcessaPdf.class.php"); require_once 'lib/phplot-5.5.0/phplot.php'; //$words = ProcessaPdf::geraArrayPalavrasChave(); $plot = new PHPlot(640 , 480); $data = array( array('1940' , 6.2 ), array('1950' , 6.2 ), array('1960' , 6.3 ), array('1970' , 5.8 ), ); $plot->SetTitle('Grafico da analise de palavras-chave encontradas'); $plot->SetPlotType("bars"); $plot->SetXLabel("Palavras"); $plot->SetYLabel("Frequencia"); $plot->SetXLabelFontSize(2); $plot->SetAxisFontSize(2); $plot->SetDataValues($data); $plot->SetYDataLabelPos('plotin'); $plot->DrawGraph(); ?></pre> <p>如果我取消注释<code>//$words = ProcessaPdf::geraArrayPalavrasChave();</code>这一行,图表就会失败</p> <p>所以我不能用$word替换$data</p> <p>返回$words的函数:</p> <pre class="brush:php;toolbar:false;">static function geraArrayPalavrasChave(){ $p_chaves = file("./lib/palavras_chave.txt", FILE_TEXT | FILE_IGNORE_NEW_LINES); // Initialize and load PDF Parser library $parser = new SmalotPdfParserParser(); // Source PDF file to extract text $file = 'lib/projeto.pdf'; // Parse pdf file using Parser library $pdf = $parser->parseFile($file); // Extract text from PDF $text = $pdf->getText(); for($i=0; $i<count($p_chaves); $i++){ if(substr_count(' '.$text.' ', ' '.$p_chaves[$i].' ') != ''){ $dados[$i][] = $p_chaves[$i]; $dados[$i][] = substr_count(mb_strtoupper(' '.$text.' '), mb_strtoupper(' '.$p_chaves[$i].' ')); } } for($i=0; $i<count($dados); $i++){ $key[] = $i; } $arrayPalavras = array_combine($key, $dados); return $arrayPalavras; }</pre> <p>我尝试从$words数组生成图表</p> <p>更新</p> <p><code>$words = ProcessaPdf::geraArrayPalavrasChave();</code></p> <p>返回数组:</p> <pre class="brush:php;toolbar:false;">Array ( [0] => Array ( [0] => inovações [1] => 3 ) [1] => Array ( [0] => tecnologia da informação [1] => 2 ) [2] => Array ( [0] => intelectuais [1] => 4 ) [3] => Array ( [0] => patente [1] => 5 ) )</pre> <p><br /></p>
P粉211273535P粉211273535448 天前545

全部回复(2)我来回复

  • P粉635509719

    P粉6355097192023-08-21 20:06:52

    我解决了这个问题。 我在composer中更新了pdfparser库,然后更新了autoload。 问题不在phplot中,而是在pdfparser中。

    回复
    0
  • 取消回复