如果可能的话,我想在PHPLOT上寻求帮助。图表在使用虚拟数据时正常显示,但是当我调用$words数组时,图表不显示。
图表代码:
<?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();
?>
如果我取消注释//$words = ProcessaPdf::geraArrayPalavrasChave();这一行,图表就会失败
所以我不能用$word替换$data
返回$words的函数:
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;
}
我尝试从$words数组生成图表
更新
$words = ProcessaPdf::geraArrayPalavrasChave();
返回数组:
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
)
)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我解决了这个问题。 我在composer中更新了pdfparser库,然后更新了autoload。 问题不在phplot中,而是在pdfparser中。