我正在尝试使用php GD生成图表。我将数据从html传递到控制器图形函数。整个过程在我的localhost上运行,但在我的实时服务器上,图形图像没有创建。我在我的本地ubuntu 14.04机器上使用PHP 5.5 ...实时服务器在debian wheezy上使用Php 5.4 ...我已经检查了两台机器GD库已安装..
在检查了一些之后,我怀疑在做urlencode和urldecode时我做错了什么,或者在创建多维数组时在我的视图中做错了。
这是我的控制器图形功能:
public function graph1()
{
include('phpgraphlib.php');
$graph = new PHPGraphLib(600,300);
$data1 = unserialize(urldecode(stripslashes($_GET['mydata1'])));
$line1 = array_column($data1, 'line1');
$line2 = array_column($data1, 'line2');
$graph->addData($line1,$line2);
$graph->setBars(false);
//$graph->setGrid(false);
$graph->setGridColor("238, 238, 238");
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor('160,160,160');
$graph->setDataValues(true);
$graph->setDataValueColor('0,0,0');
$graph->setGoalLine(.0025);
$graph->setGoalLineColor('red');
$graph->setLineColor("255, 167, 78", "67, 162, 255","blue");
//$graph->setLegend(true);
//$graph->setLegendTitle("Apples", "Pears");
$graph->createGraph();
}
以下是我传递数据的视图:
<?php
$data1 = array();
foreach ($line1 as $field => $label){
if (count($points) > 0 && isset($points[0]->$field)){
$i = 0;
$total = count($points);
$total = $total > 30 ? 30 : $total;
foreach ($points as $point){
if ($i >= $total){
break;
}
$data1 []['line1'] = $point -> $field;
$i++;
}
}
}
foreach ($line2 as $field => $label){
if (count($points) > 0 && isset($points[0]->$field)){
$i = 0;
$total = count($points);
$total = $total > 30 ? 30 : $total;
foreach ($points as $point){
if ($i >= $total){
break;
}
$data1 []['line2'] = $point -> $field;
$i++;
}
}
}
<img src="<?php echo site_url('/g1/g2/graph1')."?mydata1=".urlencode(serialize($data1)); ?>" />
此代码不是在实时服务器上创建图像..如果有人可以建议我做什么,真的很棒吗?
以下是来自我的localhost的imgsrc的url值:
http://localhost/site/index.php/g1/g2/graph1?mydata1=a%3A12%3A%7Bi%3A0%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A2%3A%2292%22%3B%7Di%3A1%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A2%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22110%22%3B%7Di%3A3%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22100%22%3B%7Di%3A4%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22365%22%3B%7Di%3A5%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22185%22%3B%7Di%3A6%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22176%22%3B%7Di%3A7%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22234%22%3B%7Di%3A8%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22358%22%3B%7Di%3A9%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22201%22%3B%7Di%3A10%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A11%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22112%22%3B%7D%7D
以下是来自Live服务器的img src的url值:
https://mysite.com/index.php/g1/g2/graph1?mydata1=a%3A12%3A%7Bi%3A0%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A2%3A%2292%22%3B%7Di%3A1%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A2%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22110%22%3B%7Di%3A3%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22100%22%3B%7Di%3A4%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22365%22%3B%7Di%3A5%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22185%22%3B%7Di%3A6%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22176%22%3B%7Di%3A7%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22234%22%3B%7Di%3A8%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22358%22%3B%7Di%3A9%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22201%22%3B%7Di%3A10%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A11%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22112%22%3B%7D%7D
此外,如果我设置pdf debug tru,那么在实时服务器中显示此调试错误:
mPDF error: IMAGE Error (https://mysite.com/index.php/g1/g2/graph1?mydata1=a%3A12%3A%7Bi%3A0%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A2%3A%2292%22%3B%7Di%3A1%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A2%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22110%22%3B%7Di%3A3%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22100%22%3B%7Di%3A4%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22365%22%3B%7Di%3A5%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22185%22%3B%7Di%3A6%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22176%22%3B%7Di%3A7%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22234%22%3B%7Di%3A8%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22358%22%3B%7Di%3A9%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22201%22%3B%7Di%3A10%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A11%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22112%22%3B%7D%7D): Could not find image file
答案 0 :(得分:0)
正如您所发现的,PHP函数array_column
开始使用PHP 5.5。
http://php.net/manual/en/function.array-column.php (PHP 5&gt; = 5.5.0)
因此,对于5.4友好代码,您可以替换:
$line1 = array_column($data1, 'line1');
$line2 = array_column($data1, 'line2');
使用:
$line1 = array();
$line2 = array();
foreach ( $data1 as $line_array ) {
if ( isset($line_array['line1']) ) { $line1[] = $line_array['line1']; }
if ( isset($line_array['line2']) ) { $line2[] = $line_array['line2']; }
}
您可以在此处进行演示:http://writecodeonline.com/php/
<?php
$data1 = array(
array('line1' => 165)
, array('line1' => 180)
, array('line1' => '')
, array('line1' => 140)
, array('line2' => '')
, array('line2' => 50)
, array('line2' => 68)
, array('line2' => 80)
);
$line1 = array();
$line2 = array();
foreach ( $data1 as $line_array ) {
if ( isset($line_array['line1']) ) { $line1[] = $line_array['line1']; }
if ( isset($line_array['line2']) ) { $line2[] = $line_array['line2']; }
}
print_r($line1);
print_r($line2);
?>
print_r
-ing $ line1和$ line2给了我:
Array
(
[0] => 165
[1] => 180
[2] =>
[3] => 140
)
Array
(
[0] =>
[1] => 50
[2] => 68
[3] => 80
)