Jpgraph or other plot tool


I had a running cakephp1.3 version several years ago and am now trying to built it new with cakephp4.x, I am not at all experienced with php or cakephp, but as I manged to do it in the past, I hope I will successful also this time with your support. My application also displays scientific data and I need to display a lot of plots. In the past I have used jpgraph for that. Do you recommend anything different?

Could you please point me into the right direction where to put the downloaded jpgraph code? Into the vendors directory?

I want to display data stored in the table “measurements”, is it correct to put the code to put the code into the measurementsController? Like

public function graph()
App::import(‘Vendor’, ‘jpgraph/jpgraph’);
$graph = new Graph();


What is the correct syntax to include jpgraph? In the past this was

To reformulate my question:

How can do I need to translate this php-syntax into cakephp4-syntax?

require_once (‘path/jpgraph/jpgraph.php’);
$graph = new Graph(350,250);

When I put that three lines into a public function into one my controllers I get an error message in the second line “Class ‘App\Controller\Graph’ not found”

That’s a much better question, with an actionable error message. :slight_smile:

CakePHP 4 uses namespaces. Your controller is in the App\Controller namespace, hence when you reference a class name without a namespace, it assumes it’s in the same one. (In CakePHP 1.x, everything was in the global namespace, so this wasn’t an issue.)

The simple solution here is to use $graph = new \Graph(...); (assuming that Graph is actually in the global namespace, which you’ll be able to tell by looking at the top of path/jpgraph/jpgraph.php.