phpjpgraph

The "jpgraph" not working, without errors in html


This is my PHP code:

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();

Reference: JpGraph Example - Chart

This is my HTML:

image

There is no error message on screen. Browser's console is empty as well.

What could be wrong? Do I need to set up something?

I have tried this link: jpgraph doesn't work but without success.


Solution

  • make sure you have at least minimal "installation" of jpgraph, this is what needs to be (at least) in your 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
    

    also be sure to have GD library enabled, if you can't access filesystem, turn off USE_CACHE in jpg-config.

    as I wrote in comment, your code works fine with default installation (means I just extracted files listed above, added your code to chart.php in root and I get the image of 3 bars in 4 groups ..

    EDIT: additionally, check troubleshooting tips in their docs and this SO topic, which is related to your problem too