![]() |
Bar Chart in PHP
Yes its that time again another chart tutorial. This one is going to be a simple bar chart :-)
You can view a demo HERE Firstly we are going to set a header type as image PHP Code:
PHP Code:
PHP Code:
Now we can create the actual chart background or where the chart is actually shown on. However you want to look at it. PHP Code:
Now we can set the background colour of the graph and also create some colours we are going to use for the bars and the lines. PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
Full Code PHP Code:
|
I've never actually tried to do a bar chart in PHP before! But if it's so easy then I sure will be adding it when I think the website would suit one. I always imagined it'd be rather difficult and that you'd need a 3rd party tool to create them. I forget its name, but there is one out there that does this all for you.
I was messing about with the GD library only the other day, so maybe I should keep going! It encouraged my to look deeper into it after I realised you could apply all sorts of fancy effects to your pictures, and I also found out how to take a screenshot of a website using GD and the Windows COM component. |
Yes i have been trying to figure out how to take screenshots of websites. I found out about the screengrab functions PHP has to offer well the latest version. I cant manage to get them to work maybe you can enlighten me on the subject? :-)
PHP Code:
PHP Code:
PHP Code:
|
Do you get a black screen? If so then you'll need to open up services.msc, go to properties for the Apache service, click the "Log On" tab then tick the box "Allow service to interact with desktop".
|
Thank you! :-) Works
|
They should tell you about that on the php.net website. If you could do back-links I might have actually posted, but as you can't, sod them!
|
Screen shots are only for windows though...correct me if I'm wrong.
|
Yea. Unfortunately the COM component is only available on Windows. Although maybe it'll work if you have Wine installed? I'm not sure as I'm not into Linux that much, but it's just an idea.
|
Haven't ran into that specific problem before so it shouldn't pose a problem. We kinda use the same charts (this one is a little bit more degraded AND advanced at the same time) but no errors yet.
PHP version? |
I believe version 4 - 5
|
There is a nice graph extension, namely JPGraph (http://www.aditus.nu/jpgraph/)
|
Yes i have heard of this..tis very good..
|
Although I've never tried the technique you use here to create a single image with php only, wouldn't it be better and easier to use html and some css to set the height of the bars for example?? It would be more accessible since people can still view the data because the numbers are displayed as html text instead of an image.
Thanks for the tutorial though, I'm not that experienced with php and might use this to add some text to thumbnail images. I'm wondering if it's possible to adjust the opacity of a certain rectangle you're creating for example, any ideas? |
I was just looking through google about this function imagegrabscreen() and I thought Id sign up on this forum to mention that there are potential security risks in activating the "Allow service to interact with desktop". As far as Im aware this is only available for windows servers and since I only have access to a shared Unix server from my host I cant test the theory. However M$ do advise strongly that this service never be used! :-P
Id rather mention it than not as I was quite excited at the idea of being able to capture the screens of visitors... Then I thought some more... isnt this a break in some privacy law (UK / US)??? :-/ Anyway, cant test it so unsure on what exactly can be produced. Kind regards Dal PS: didnt this thread start of with something completely different???:-/ |
Check this out, very nice tutorial on drawing bar graph with php
How to create bar graph in PHP with dynamic scaling |
bar graph is not working in any html tags?
hi when i m using the above given script in any html tag or even i m giving any html tag above or below this code... the functionality of script stops. a garbage value is seen...
i hv to put this bargaraph in a html page which contain some other data alos.. what to do... plz give me soloution |
Quote:
|
Quote:
plz.... thanks |
We can't help you without knowing the problem. A short paragraph saying "it doesn't work!" is no use at all. Give us a live example of the problem, turn on error reporting, show us source code.
|
Quote:
thanks |
| All times are GMT. The time now is 12:36 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0