Bargraph



This is the code for a simple bargraph with comments
caption.png
podpis
what each line does.
 <?php
 
 
 
 // Storing the data in an array makes it easy to loop through
 
 // when adding later, but it can also be added one value
 
 // at a time
 
 $data = Array(10,20,30,40,50,40,30,20,10,0,-10,-20,-10,0,10,20);
 
 
 
 // Next, create a new instance of Sparkline_Bar
 
 $graph = new Sparkline_Bar();
 
 
 
 // Set the width of each bar in the graph
 
 $graph->setBarWidth(4);
 
 
 
 // Set the spacing between the bars
 
 $graph->setBarSpacing(2);
 
 
 
 // Add a color called "mygray" to the available color list
 
 $graph->setColorHtml("mygray", "#424542");
 
 
 
 // Set the background color to this new color
 
 // As of 0.2, if you didn't set the color beforehand,
 
 // your background would be black
 
 $graph->setColorBackground('mygray');
 
 
 
 // Begin the loop to add the data
 
 foreach ($data as $key => $value) {
 
 
 
 // Add the data
 
 // This will make one white bar with the relative value
 
 // of $value
 
 $graph->setData($key, $value, 'white');
 
 }
 
 
 
 // Draw all necessary objects for our graph
 
 // The height will be 16
 
 $graph->render(16);
 
 
 
 // Displays the graph by sending a 'Content-type: image/png'
 
 // header then outputting the image data
 
 echo $graph->output();
 
?>