Click here to Skip to main content
14,120,083 members
Rate this:
 
Please Sign up or sign in to 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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[^]
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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?
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190518.1 | Last Updated 26 Apr 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100