"jpgraph" 不工作,在 html 中没有错误
The "jpgraph" not working, without errors in html
这是我的 PHP 代码:
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/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();
这是我的 HTML:
屏幕上没有错误消息。浏览器的控制台也是空的。
有什么问题吗?我需要设置什么吗?
我试过这个link:jpgraph doesn't work但没有成功。
确保您至少有最少的 "installation" jpgraph,这是您 root
中(至少)需要的内容:
-chart.php
-jpgraph
-fonts
-FF_FONT0.gdf
-FF_FONT0-Bold.gdf
-FF_FONT1.gdf
-FF_FONT1-Bold.gdf
-FF_FONT2.gdf
-FF_FONT2-Bold.gdf
-themes
-UniversalTheme.class.php
-gd_image.inc.php
-imageSmoothArc.php
-jpg-config.inc.php
-jpgraph.php
-jpgraph_bar.php
-jpgraph_errhandler.inc.php
-jpgraph_gradient.php
-jpgraph_legend.inc.php
-jpgraph_plotband.php
-jpgraph_rgb.inc.php
-jpgraph_text.inc.php
-jpgraph_theme.inc.php
-jpgraph_ttf.inc.php
还要确保启用GD library
,如果无法访问文件系统,请在jpg-config
中关闭USE_CACHE
。
正如我在评论中所写,您的代码在默认安装下运行良好(意味着我刚刚提取了上面列出的文件,将您的代码添加到根目录中的 chart.php,我得到了 3 条 4 组的图像。 .
编辑:另外,检查 troubleshooting tips in their docs and this SO topic,这也与您的问题有关
在任何情况下你都在使用 Laravel,你可以使用这个 https://github.com/HuasoFoundries/jpgraph (it is not official composer package of jpgraph as they claim 但它很有用,示例也写在 repo 中)。
测试时,我也得到了一个小灰框而不是图表。
但添加 ob_end_clean();
(refer php.net doc、— 清理(擦除)输出缓冲区并关闭输出缓冲)修复了它。而且我能够渲染图表。
输出:
这是我的 PHP 代码:
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/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();
这是我的 HTML:
屏幕上没有错误消息。浏览器的控制台也是空的。
有什么问题吗?我需要设置什么吗?
我试过这个link:jpgraph doesn't work但没有成功。
确保您至少有最少的 "installation" jpgraph,这是您 root
中(至少)需要的内容:
-chart.php
-jpgraph
-fonts
-FF_FONT0.gdf
-FF_FONT0-Bold.gdf
-FF_FONT1.gdf
-FF_FONT1-Bold.gdf
-FF_FONT2.gdf
-FF_FONT2-Bold.gdf
-themes
-UniversalTheme.class.php
-gd_image.inc.php
-imageSmoothArc.php
-jpg-config.inc.php
-jpgraph.php
-jpgraph_bar.php
-jpgraph_errhandler.inc.php
-jpgraph_gradient.php
-jpgraph_legend.inc.php
-jpgraph_plotband.php
-jpgraph_rgb.inc.php
-jpgraph_text.inc.php
-jpgraph_theme.inc.php
-jpgraph_ttf.inc.php
还要确保启用GD library
,如果无法访问文件系统,请在jpg-config
中关闭USE_CACHE
。
正如我在评论中所写,您的代码在默认安装下运行良好(意味着我刚刚提取了上面列出的文件,将您的代码添加到根目录中的 chart.php,我得到了 3 条 4 组的图像。 .
编辑:另外,检查 troubleshooting tips in their docs and this SO topic,这也与您的问题有关
在任何情况下你都在使用 Laravel,你可以使用这个 https://github.com/HuasoFoundries/jpgraph (it is not official composer package of jpgraph as they claim 但它很有用,示例也写在 repo 中)。
测试时,我也得到了一个小灰框而不是图表。
但添加 ob_end_clean();
(refer php.net doc、— 清理(擦除)输出缓冲区并关闭输出缓冲)修复了它。而且我能够渲染图表。
输出: