Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to implement a graph in php.
Using Google chart it may be possible But it's in javascript code.
Is there any library file are available in PHP for creating a graph ?

What I have tried:

I tried google chart but it's in javascript .
Posted
Updated 26-Apr-19 1:40am
v2
Comments

Separation of Concerns comes into play here.

The Chart is presentation layer and should be one of the last things to do; easiest way to do it would be via JavaScript on the actual webpage.

PHP is server-side, and will play the roles of the Business Layer as well as the Data Layer.

So how do you apply this?
You get all of your data and process this data into the data-set you want to display on the web page. This data-set can be injected directly into the HTML via inline PHP.
Another option would be to have this data-processing in a separate PHP script and call it via AJAX.
Regardless of which of the above methods you choose; once that data-set is available you use JavaScript to work through the data-set and build the chart using the library of your choice.
 
Share this answer
 
Quote:
How to create graph in PHP

First of all, php is server side language, it is used to prepare page that will be sent to client browser.
JS and html are client side.
There is basically 3 ways to make a graph in an html page.
- The canvas which is manipulated on client side by some JS code.
- A picture which is on server or made by php code on server side.
- A SVG graph which is prepared on server, SVG is either a file or embedded in the html page.
This site is a good starting point: W3Schools Online Web Tutorials[^]
SVG Tutorial[^]
PHP 5 Tutorial[^]
 
Share this answer
 
PHP runs on the server. Javascript runs on the client and is precisely what you need to use, unless you're determined to generate a static bitmap on the back end and then serve it. I'v never used PHP, but, I imagine it could only do that via a COM object?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900