【问题标题】:php jpgraph page all whitephp jpgraph页面全白
【发布时间】:2017-01-03 23:21:27
【问题描述】:

我正在尝试从this 站点加载条形图示例:

这是我的代码:

error_reporting(E_ALL); ini_set('display_errors', '1');

chdir("/path/lib/jpgraph-4.0.1");
include ("jpgraph.php");
include ("jpgraph_bar.php");


$data1y=array(47,80,40,116);
$data2y=array(61,30,82,105);
$data3y=array(115,50,70,93);


// Create the graph. These two calls are always required
$graph = new Graph(350,200,'auto');
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);

$graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135));
$graph->SetBox(false);

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b2plot = new BarPlot($data2y);
$b3plot = new BarPlot($data3y);

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
// ...and add it to the graPH
$graph->Add($gbplot);


$b1plot->SetColor("white");
$b1plot->SetFillColor("#cc1111");

$b2plot->SetColor("white");
$b2plot->SetFillColor("#11cccc");

$b3plot->SetColor("white");
$b3plot->SetFillColor("#1111cc");

$graph->title->Set("Bar Plots");

// Display the graph
$graph->Stroke();

如果我评论“$graph->Stroke();”行,则显示页面(没有图表),但是使用此行,页面全白,没有错误,没有其他字符串显示

在 php 错误日志或 apache 日志上我没有错误

编辑:问题已解决。

我将图表代码放在其他页面(例如chart.php),而不是放在主页面:

<img src="chart.php" />

其他解决方案是使用命令创建一个 png 文件:

$myPicture->Render($fileName); 

然后在主页上

<img src="<?php echo $filename" />

【问题讨论】:

    标签: php jpgraph


    【解决方案1】:

    您必须删除图形文件中 php 第一行之前的任何空格,因为任何空白行都被视为回显“”;并且图形文件应该没有 echo 或 print..etc.. 然后在其他文件中使用 img 标签来显示图形.. 对我来说,我将文件命名为 graph.php,我将另一个 stat.php 命名为 lats我写了..你可以在同一个图形文件中从 mysql DB 导入数据,但永远不要在那里 ^print 它们。只使用数据库中的数组作为图表的收入数据..对不起,我使用英语,因为我的法语不是那么好

    【讨论】:

    • 你知道为什么 echo 语句会使图表不显示吗?
    【解决方案2】:

    在要更改的路径末尾添加一个斜杠:

    chdir("/path/lib/jpgraph-4.0.1/");
    

    【讨论】:

    • 问题不在于路径,而在于我如何调用图表库
    猜你喜欢
    • 2015-12-03
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 2017-05-23
    • 1970-01-01
    相关资源
    最近更新 更多