Hi all,

I need to create a bar graph using php, the values of x-axis and y-axis are dynamic coming from database, Am trying my best to do it but finding it difficult. Has anyone done this or is there php library files for doing this.

Thanks,
Shakeeb

    Simple bar graphs can be easily made by using 1-pixel images that are sized based on the retrieved data.

    <img src='/images/green.gif' width='20' height='<?php 
    echo round($valueFromDb * $scalingFactor); ?>' alt='<?php echo $valueFromDb;?>' />
    

    For more complex graphing, there are a number of 3rd-party packages you could try. For instance, see: http://sourceforge.net/search/?type_of_search=soft&words=%28%2Bphp+%2Bgraph%29+AND+-has_file%3A%280%29&search=Search.

      It depends on what sort of graphs you need to produce. For ones with very small data sets, Google has a graph API that is very easy to use with little to no server-side code needed.

      For things that are a bit more complex and where you need some more control, then look at Pear Graph, which is a very powerful PHP graph class.

        I used ChartDirector for a project and was very happy with it. I don't think it's free though.

        I've also used nogdog's approach. You can create a <div> or <span> tag or <img> with a particular color and size it. You kind of have to write the code to scale everything though but it's not particularly difficult. It's only good for bar graphs though. If you want pie charts or line charts then you need some kind of library that will render an image.

          Write a Reply...