tags:

views:

132

answers:

5

HI. I wanted to know if we could create pie and bar charts based on info from the database on a php website. I want to grab some information from the database and show it as an image so better analysis. Is there anyway to do this?

Also, If i am using fpdf to generate pdfs from php and mysql, can i also design pie charts in that pdf and show it as an image in that?

A: 

I'd recommend using tcpdf instead of fpdf. fpdf was pretty good, but is no longer actively developed. tcpdf is. http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf

As for the graphs there are many libraries displaying image graphs like http://jpgraph.net/ or client side JS libraries that will create flash graphs like ExtJS

Mchl
If you want flash graphis http://www.maani.us/xml_charts/ is another good xml/swf graphing library.
David Young
Thank you for your replies :)
Scorpion King
A: 

JpGraph is a pure php library for generating graphs which outputs an image. I'm not familiar with fpdf but if it can embed images then this solution should work out.

http://jpgraph.net/

David Young
Yes, FPDF can embed images. TCPDF can too.
Mchl
Thank you for your replies :)
Scorpion King
A: 

I'm using ChartDirector (not free) and FPDF to do this (today as a matter of fact).

ChartDirector can write the chart to a file, which I stick in /tmp. Then I import the file into the PDF file. Then I delete the file from the disk. Then I do it twenty more times with different data.

I'm sure any chart library that can write to disk will work. With FPDF, you can set the size of the image you import. So here's a trick: create the chart image twice as large as you need it and tell FPDF to place it at the size you want. This way, you'll get an image in the PDF file at around 144 dpi (assuming your library exports at 72dpi for the screen). You'll have a PDF that doesn't look as pixelated when zoomed in, and it will print better.

Scott Saunders
+2  A: 

You could use the Google Chart API

Ed
A: 

Check out this article on A List Apart for a method using the Raphael javascript graphics library. It demonstrates how to take a generic HTML table and replace it with a cross-browser, dynamic, scalable pie chart. The same could probably be done for a bar chart.

The advantage of this method is semantically correct markup - useful for users without JavaScript, as well as bots and screen readers.

Ryan Kinal