I would like to create a stacked bar chart based on data from a text file USING PHP ... ( The file name must be on the x axis ... n based on the data read inside the file, y axis stack bars must be populated )
If you could provide me with code snippets and suggest the best libraries to use for this specific "dynamic stacked bar graph " creation, it'd be really helpful .
Thanks a lot
What format is your data in?
I've used, and like pChart (The site has good examples). There is a new version out but I have yet to use that. They can do stacked bar charts
Fusion charts has both a free and paid version. The paid version has stacked bar charts (Not sure about the free) and they have examples on their site.
Both can be dynamic in generating graphs. It really depends on your needs.
If it does not HAVE to be PHP there are javascript options that can read data from a file as well.
This is kind of a broad question, and it seems like some Googling might be useful here.
That being said, I'd take a look at Highcharts. It's a JavaScript library that draws graphs based on input data, which can easily be generated using PHP.
I currently use it with a Ruby on Rails app, and it works really well.
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.
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.
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 need to generate a line graph based on results within a MySQL database, any ideas?
I must also point out that I do not have administrator rights to install things such as JGraph.
Google has a pretty comprehensive charting API available via javascript calls or simply image links. http://code.google.com/apis/charttools/index.html
You can use the GD library, right?
Should be able to use that to do a line graph as an image. You'd have to determine a scale and all that and figure out how to map that to the X and Y coordinates of the image, and then use that to plot the numeric data to the graph and use imageline() to draw the lines for it.
It would be the most compatible method. Java can be turned off and Flash isn't universally supported.
I don't want to give you a specific library to use, but if you searched google for "flash graph", you'll find a ton of flash graphic software. See http://www.google.ca/search?q=flash+graph&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
Note, these don't require anything to be installed on your server (unlike how jpGraph requires GD).
Check out PHP/SWF Charts.
To support mobile devices, you can use a JavaScript charting library such as Flot (http://code.google.com/p/flot/).
Example : http://people.iola.dk/olau/flot/examples/basic.html
This would work for desktop (IE / Firefoex /Chrome / Safari) as well as mobile (iOS / Android / Blackberry ).
jqPlot has come on in leaps and bounds recently.
A few stand out features from my point of view:
Proper implementation of rotated axis labels/text (Google charts can't do this)
Ability to plot many graph types including bubble and candlestick plots (like box and whisker plots)
jQuery based so easy to integrate if you are already using jQuery
Doesn't require an externally hosted API
Free
Features from their site:
Numerous chart style options.
Date axes with customizable formatting.
Up to 9 Y axes.
Rotated axis text.
Automatic trend line computation.
Tooltips and data point highlighting.
Sensible defaults for ease of use.
I am using jqPlot in a large project at the moment after trialling the following "competitors":
Protovis
amCharts
Google Charts
Highcharts JS
RGraph
PHPs GD lib
flot
And for fun here is a fully working ASCII pie chart written in pure SQL: http://code.openark.org/blog/mysql/sql-pie-chart
You can make an bar-graph relatively easy with php, html and css.
HTML/CSS part: As pointed out by Col. Shrapnel above:
It's as easy as elementary school math
and basic HTML just a couple divs
of this kind
<div style="background-color:black;width:50%;"> </div>
<div style="background-color:black;width:30%;"> </div>
<div style="background-color:black;width:20%;"> </div>
Custom bar images: If you would like a slightly fancier bars, you can use your own customs images, manipulated trough the width: CSS property of the < img /> tag.
The search query bellow contains at least 2 comprehensible and easy tutorials, on how to make your own bar graph with PHP/
google search for detailed tutorials
This approach should be less resource consuming on the end-user's computer, compared to JavaScript APIs.
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.