TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack (5) Thread Tools Search this Thread Display Modes
Old 09-18-2009, 05:11 PM   #21 (permalink)
The Visitor
 
Join Date: Sep 2009
Posts: 1
Thanks: 0
raulursu is on a distinguished road
Default

You can use ws_charts with this tutorial:

http://www.webstorm.ro/manuals/WS%20Charts-En.htm
raulursu is offline  
Reply With Quote
Old 03-23-2010, 01:02 PM   #22 (permalink)
The Visitor
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
shafiq2626 is on a distinguished road
Default Not Displaying Chart on my web page

Quote:
Originally Posted by Rendair View Post
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:
 header("Content-type: image/jpeg"); 
Now we are going to set some values in an array to use and then all them all together
PHP Code:

$data 
= array('3400','2570','245','473','1000','3456','780');
$sum array_sum($data); 
Now we need to set the height and width of the actual chart itself.

PHP Code:
$height 230;
$width 320
For the sake of this tutorial do not edit this. Otherwise this may cause errors.

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:
$im imagecreate($width,$height); // width , height px 

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:
$white imagecolorallocate($im,255,255,255); 
$black imagecolorallocate($im,0,0,0);   
$red imagecolorallocate($im,255,0,0); 
Now its time to create the X & Y axis lines.

PHP Code:

imageline
($im10510230$black );
imageline($im10230300230$black); 
PHP Code:
imageline  resource image,x-coordinate first point,y-coordinate first point,x-coordinate second point,y-coordinate second point,colour 
Now we need to set up some information so we can place these bars.

PHP Code:

$x 
15// set how far from the side then how far from next bar
$y 230// set where bar should reach on the y in this case on the y line we created
$x_width 20// Width of each of the bars 
$y_ht 0//height of the bars 
Now we can start creating the bars themself.

PHP Code:
for ($i=0;$i<7;$i++)
{
        
  
$y_ht = ($data[$i]/$sum)* $height// work out height and make sure they don't go larger then the image    

     
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
     
imagestring$im,2,$x-1,$y+10,$data[$i],$black);
              
  
$x += ($x_width+20); // set the new distance for the next bar 
         

Now we can display the final results

PHP Code:
imagejpeg($im); 
This bar chart can easily be upgraded and i will be in the next advance tutorial on bar graphs. Stay tuned.

Full Code
PHP Code:
<?php
  
           header
("Content-type: image/jpeg");
         
        
// read the post data
        
$data = array('3400','2570','245','473','1000','3456','780');
        
$sum array_sum($data);
        
        
$height 255;
        
$width 320;
        
        
$im imagecreate($width,$height); // width , height px

        
$white imagecolorallocate($im,255,255,255); 
        
$black imagecolorallocate($im,0,0,0);   
        
$red imagecolorallocate($im,255,0,0);   


        
imageline($im10510230$black);
        
imageline($im10230300230$black);
    

        
$x 15;   
        
$y 230;   
        
$x_width 20;  
        
$y_ht 0
       
        for (
$i=0;$i<7;$i++){
        
          
$y_ht = ($data[$i]/$sum)* $height;    
          
              
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
              
imagestring$im,2,$x-1,$y+10,$data[$i],$black);
              
          
$x += ($x_width+20);  
         
        }
        
        
imagejpeg($im);

?>
Hi!
I used code given above but this not displaying any chart on my web page.
Only Display Cros Image in IE and In Mozilla Display only loaclahost address.
please help me in this problem with thanks
shafiq2626 is offline  
Reply With Quote
Old 05-12-2010, 07:22 AM   #23 (permalink)
The Wanderer
 
Join Date: May 2010
Posts: 7
Thanks: 0
Torsten is on a distinguished road
Default

I think pChart is a good framework for drawing Charts.

http://pchart.sourceforge.net/
Torsten is offline  
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/advanced-php-programming/1629-bar-chart-php.html
Posted By For Type Date
Datuve :: Forums :: Kaa lapaa dinamiski izveidot diagramu vai grafiku? This thread Refback 01-03-2008 05:46 PM
Drawing anti-aliased lines using the GD library - PHP This thread Refback 12-31-2007 02:22 AM
Drawing anti-aliased lines using the GD library - Object Mix This thread Refback 12-30-2007 03:45 AM
Drawing anti-aliased lines using the GD library - alt.comp.lang.php | Google Groups This thread Refback 12-29-2007 04:50 AM
Drawing anti-aliased lines using the GD library - Usenet Forums This thread Refback 12-23-2007 06:53 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:20 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design