How can I generate a graph based on data inside my database? For example, I want to display the traffic of a website between a 90 day span, and a graph will display this, like a line graph. I don't like the PHP image and GD functions, they are really pixelated and are actually PHP pages acting like images. I'm not sure if this is how I've seen it done on other websites, but I would like a smooth image.
Great question one awesome solution that i have done is to use: http://code.google.com/apis/chart/ The Google Chart has lots of great graphs etc.. you can use. What i did was look at the examples see how the data was formatted, then I wrote my query to match it.
Related
I'm looking for quite a specific technique.
The short of it:
I need HTML which can generate a line chart, as shown below (but without the background image. That is totally irrelevant)
However, I want to make it in HTML, without Javascript or Flash and in a way that the dots can be hovered to show more information.
The long of it:
The image shown above comes from the website jpgraph.net. That is a PHP library for creating charts. The downside of that however, is that it generates images. Since you have no clue of knowing where the dots are going to end up, you can't estimate where the hovers should be made.
Ofcourse there are also loads of javascript ways of doing this, but the graph should also work without javascript.
Flash is out of the question, since it should also work on tablets (read iPads)... And because it is flash...
All the information shown in the graph is generated by an external system. That means that the code should work and change the graph, depending on the information put in there.
EDIT:
I'm aware of the fact that it is easily done with javascript, and my fallback would be to offer a javascript version and as a fallback the php version. However, I'm hoping to find a way which doesn't need a fallback. Using 1 script to do the same task would be better than using two.
You should check out Charts.js by Nick Downie.
It has simple HTML5 Charts using the canvas element -
Charts and Graphs Included:
Bar Chart
Doughnut Chart
Line Graph
Pie Chart
Polar-area Chart
Radar Chart
Read the documentation here: http://www.chartjs.org/docs/
and download on GitHub here: https://github.com/nnnick/Chart.js
Hope I Helped
For those still interested: I fixed this using the jpgraph.net library. It's a php library which allows you to draw graphs on the server using data you get from somewhere else.
As enhzflep pointed out, since you have the data, you can calculate where the points will end up. This is however, quite a tedious job, but it's working in javascript-less browsers.
ive been reading up on QR Codes a lot recently, I want to code my own generator with PHP. But i'm having trouble, as they are rather complicated, does anyone know of any tutorials for this sort of thing?
I found this, but I get stuck when trying to convert the result from page 3 to a 11-bit binary result. I'm also confused as to why "H" ASCII value is 17 on that table, but it is 72 on the ASCII table below...
The main issue i'm having is generating it, I was thinking about using a table for the pixels. I want to eventually be able to generate my own QR Code like the one below, but different text in the middle and different content:
I would suggest that you do NOT use tables for generating QR codes. This is way too much overhead for the browser, and if a browser renderes the box model that is off by 1 pixel, your whole image will be crap.
I would take a look at generating your images on the sever in php using GD2.
http://phpqrcode.sourceforge.net/
http://www.youtube.com/watch?v=sFVcOFmnZ9Y
If you really want to generate images inside the browser, you could probably get away with a HTML canvas tag.
If you want to add text I suggest you layer the text on-top using GD2. If you are using an SVG library I'm not exactly sure how to layer, but it should be simple. Here's an example of layering in GD2:
http://phpimageworkshop.com/
The thing to realize about QR codes is that they can store up to 30% redundant data. That means that you can "destroy" 30% of the code by layering an image on-top and it will still work. Here are some guides about customizing QR codes with logos etc:
http://blog.qr4.nl/post/QR-Code-Error-Recovery.aspx
http://mashable.com/2011/04/18/qr-code-design-tips/
There are many php classes and external libraries available to generate QR code using php. I have listed some of them below. You can refer these links.
http://phpqrcode.sourceforge.net/
http://www.phpclasses.org/package/6399-PHP-Generate-QR-Code-images-using-Google-Chart-API.html
http://qrcodescript.com/
I sampled a small wikipedia collection from 2008 and trying generate a graph similar to this: http://en.wikipedia.org/wiki/File:Wikipedia-n-zipf.png
from the processing I did. I have word frequencies and ranks of words. How can I generate the graph on the fly from the data I collected? Thanks.
If I am understanding your question correctly, you want to generate PNG charts on the fly?
This Page lists a few great chart engines for PHP. If you want to generate graphics using PHP for word frequencies, my personal favorite is PCHART It is a really nice library to generate charts like that.
Google Chart is completely free and doesn't use as much server power, but you have much less control over caching, styling, etc. The key difference here is that the actual image generation is done by Google.
If you want it to look exactly like that, you can use any of them and use the most basic settings to get what you need.
I think you want to use the google chart api / graph tools.
You can find it here
Line charts documentation and examples
I'm building a PHP web app which requires a dynamic list of images, based on a MySQL database. For example, if the database consisted of "house", "car", and "plane", I'd like to display three images of a house, a car, and a plane. I do not want to store these images locally, because the database will be constantly changing. Instead, I'd like it to query Google Images using PHP and then generate an image URL that I can echo to HTML to display the image. Even better, if it could be customized with a random image index (so it won't use the first image every time), that would be even better.
Can anyone help? Thanks!
Google used to have an image search api (http://code.google.com/apis/imagesearch/) but that has been deprecated. If you need a reliable method I would not advise using anything that is deprecated but that is up to you and your application spec.
Another way would be to curl www.google.com/search?tbm=isch&q= and scrape the html that is returned. I believe that this is against Google's TOS so again use with caution.
I would suggest looking into other services than Google. Here is Bings api doc (http://msdn.microsoft.com/en-us/library/dd251072.aspx) as an example.
I want to take data from a table that'll be almost exactly similiar to the one below, but have it in a line graph. The date values would be on the Y-axis, and it would plot the XP values on the X-axis. Since the numbers for each user vary, I'd need a way to make the distance between each point plotted "relative", I guess.
Example table http://img687.imageshack.us/img687/4175/tablel.png
Any suggestions?
If you want to generate a static image of the chart you could use Libchart or pChart for PHP.
It's better to get the data from the data source, not from the rendered table. Anyway it's two separate questions: how to take data from a table and how to draw a graph.
Drawing a chart in PHP is pretty easy. HTML/CSS can be used to draw a bar and PHP to calculate the bar length.
Or if you want to go the JavaScript route, maybe Raphaël.
I would go for HighCharts.
If you're using a linux/unix platform, you probably already have Gnuplot installed. Gnuplot can take a plot file and a datafile and generate an image, thus:
History.gnuplot, which needs to be generate first:
set title "Rawr_satch history"
set xlabel "Time"
set ylabel "Ranking"
set output "rawr_satch_graph.png"
set terminal png color
set xdata time
plot "rawr_satch_xphistory.dat" with linespoints
Which assumes a data file rawr_satch_xphistory.dat has already been generated, formatted thus:
2010-03-06 385581123
2010-03-05 384895430
2010-03-04 382983388
People have also written interfaces into Gnuplot for most languages, for example PHP-GNUPlot. Gnuplot scripts can be quite complex, and you could plot multiple variables, etc.
I use and fully recommend the Google Chart Tools API. If you're looking for a simple line-graph, they provide a very simple API that you can call that requires no installation or configuration. Some of the documentation is confusing, but I've been able to figure it out with a little bit of patience.
All that is required is an IMG tag and point the src to the Google URL with the right parameters.
They also have a more interactive Javascript library if you want to provide more functionality later on.
I've used the following from PHP: Google Charts, Open Flash Chart, YUI charts (Flash), and AMCharts (also Flash).
They're all pretty easy to use and all have their pros and cons. If you want to show more than a single graph on one page, don't use Flash-based charts. It turns out browsers have trouble displaying a dozen Flash charts all at once. AMCharts is probably the most feature rich, but the options available depend on which of their chart packages you select, and configuration is pretty complex.