开发者

creation of pie and bar charts in php website

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 som开发者_如何转开发e 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?


You could use the Google Chart API


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


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/


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜