By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

How to create bar graph dynamically using gd libraries

100+
P: 254
Hi

I have created bar graph using gd libraries and php but i want to create this graph dynamically. How can I do this? based on number of data width and height of the image will be changed.
Feb 7 '08 #1
Share this Question
Share on Google+
8 Replies


MarkoKlacar
Expert 100+
P: 296
Hi,

Well I don't know what you've got so far, in detail that is, but you need to keep track of how many bars, obeservations etc you are going to work with.

You should either calculate this or provide it in some other way.

Are you reading values from a database or in some other way?
Feb 7 '08 #2

100+
P: 110
not sure exactly what you are looking to do, or have done,
but I've been building bar graphs with css for years, and find it always works well for me.

Just set the div height or width to be dynamically output into your page and voila, instant bar chart.

Hope it helps
Feb 8 '08 #3

100+
P: 254
not sure exactly what you are looking to do, or have done,
but I've been building bar graphs with css for years, and find it always works well for me.

Just set the div height or width to be dynamically output into your page and voila, instant bar chart.

Hope it helps

I dont how you are doing it using css so. if you may please give your code so that I can try to do it using css.
Feb 8 '08 #4

100+
P: 254
Hi,

Well I don't know what you've got so far, in detail that is, but you need to keep track of how many bars, obeservations etc you are going to work with.

You should either calculate this or provide it in some other way.

Are you reading values from a database or in some other way?
presently I am not taking the data from database but later I will. I have track that how many bar I needed. thing is that when I try to give some negative values for graph it is not showing the bar. so If you need code definetly tell me.

or if you are using some thing like that please help me.
Feb 8 '08 #5

MarkoKlacar
Expert 100+
P: 296
I've made my own charts, I wasn't using php when I did mine but I stil think I can give you some pointers.

Let me know when you get stuck or need advice.
Feb 8 '08 #6

ifedi
P: 60
not sure exactly what you are looking to do, or have done,
but I've been building bar graphs with css for years, and find it always works well for me.

Just set the div height or width to be dynamically output into your page and voila, instant bar chart.

Hope it helps
Yeah, I've done a bar-graph with php and css myself. There were w major disadvantages, however, which I noted:
1. The 'bar divs' had to be absolutely positioned to work well, and there was no easy way of placing the div wrapping the bars on the page, unless the larger container-divs are themselves absolutely positioned.
2. The graphs will need a refresh each time you want the current status displayed.

I reckon that something like ajax would solve the latter problem. Unfortunately, I'm completely green, and painfully slow in ajax.

In conclusion: I still need help here!

Ifedi
Feb 8 '08 #7

100+
P: 110
I can't track down any of my old code right now, but here's the basics,

step 1 - have your php page create the div which will be the bar and the size of the bar is the width field

each bar gets it's own div, the output html looks like this
Expand|Select|Wrap|Line Numbers
  1. <div class="bar"  style=" width: width-variable ">your bar variable</div> 
  2.  
then your css sets the rest of the style for the div

Expand|Select|Wrap|Line Numbers
  1. .bar { 
  2.         height: 14px;
  3.         border: solid black 1px;
  4.         background-color: blue;
  5. }
  6.  
that's it! You can line-up your bars by setting absolute positions if necessary, etc.
Vertical bars are a bit more difficult, but can be done (I did it a LONG time ago and remember positioning it being a pain, but eventually got it working).

If memory serves me correctly, the vertical bars where made by creating a div with a set width, and then having the background image begin partway the div setting the background position in the output.

Hope it helps,
Pete
Feb 8 '08 #8

MarkoKlacar
Expert 100+
P: 296
Aren't we talking php-charts, i.e creating an image useing the gd libraries?
Or am I way off base?
Feb 11 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.