Graphs

Permalink 1 user found helpful
Hi all, Im fairly new to C5 but I want to use the GD library to generate some graphs, I have some code which follows but the main problem seems to be this line: header("Content-Type: image/png");

It says header information has already been sent
in the block controls, again I am a newbee, so sorry if im wasting your time but can anyone help?

I am using the php block to write this in, eventually I will use my database connection for the data but for now i just want to create a simple bar chart.

Thank yiu in advance

Gary

// This array of values is just here for the example.
    $values = array("23","32","35","57","12",
                    "3","36","54","32","15",
                    "43","24","30");
// Get the total number of columns we are going to plot
    $columns  = count($values);
// Get the height and width of the final image
    $width = 300;
    $height = 200;
// Set the amount of space between each column
    $padding = 5;
// Get the width of 1 column
    $column_width = $width / $columns ;
// Generate the image variables
    $im        = imagecreate($width,$height);

 
Mnkras replied on at Permalink Reply
Mnkras
where are you putting this code?
garynobles replied on at Permalink Reply
im putting the code in a php block, I could put it in a html block by adding the <php> </php> tags
Mnkras replied on at Permalink Reply
Mnkras
yea, thats not going to work (btw the php tags are <?php and ?>)

you should make a tool with the above content with the header, then in a php block, make an image tag and echo the path to the tools file, thats the simplest way
garynobles replied on at Permalink Reply
sorry muddling my php and html tags - its been a long day!

As i said im a newbee to C5, tools file? There are lots of tools folders mainly in the blocks folder.

but ok i get the image tag
<img src='path to tools file' />
Mnkras replied on at Permalink Reply
Mnkras
make a file in /tools and call it graph.php (or w/e you want) and paste the code that you wrote
Mnkras replied on at Permalink Best Answer Reply
Mnkras
oops hit reply, in a php block do this:
$urls = Loader::helper('concrete/urls');
then do
$graph = $urls->getToolsURL('graph');

then echo $graph in the image tag,
garynobles replied on at Permalink Reply
so far so good :-) thank you for your time and help... um it displays a image holder... so its wanting to display an image but not getting it...

$urls = Loader::helper('concrete/urls');
$graph = $urls->getToolsURL('graph.php');
echo "<img src='$graph' />";


phpinfo() says I have GD installed, maybe its the graph.php code... I will look for some other code. Thank you for your help, if you have any other thoughts please let me know.

Gary
Mnkras replied on at Permalink Reply
Mnkras
what is the path outputted? and what is displayed when you go to

site.com/index.php/tools/graph?
Mnkras replied on at Permalink Reply
Mnkras
oh, remove the .php from the ('graph.php')
garynobles replied on at Permalink Reply
its ok solved it... I didnt put in the <php ?> tags in the graph.php as I thought as I was using it in a php block it wouldnt work... now it works :-) thank you so much for your patience and help
Mnkras replied on at Permalink Reply
Mnkras
Cool, NP :)