Using Templates

A php-RGraph template is a pre-designed skeleton to build the html code (mainly the script tag) for displaying your chart on your website. It takes variables built by yout chart script and "renders" them into html-code. Templates are php files and are stuctured this way:
  1. template header file
  2. template body file

The template header file contains pure php code. This code is used for checking and setting of needed variables. Template header files are mostly common in their functionality and may be used in most of the template body files.

Template body files contain html and php code. This code is used to fill neccessary values for script- and html-tags. Have a look at "default.php", which is used in most of the samples I've created.

<?php include_once "default_header.php"; ?>

<canvas id="<?php echo $id; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" 
 style=" <?php echo $canvas_style; ?>" class="<?php echo $canvas_class; ?>">
    [No canvas support]>
</canvas>
<script type="text/javascript">
jQuery(document).ready(function() {
 
  <?php echo $event_script; ?>
        
  var <?php echo $chart_name; ?> = new RGraph.<?php echo $chart_type; ?> (
   <?php echo $rgraph_json; ?>).<?php echo $draw_option; ?>

   <?php echo $chart_script; ?>
});
</script>

I've marked all php code in green color - you may have detected that most of all variables have been defined by your chart script.

The red color marked include of "default_header.php" has been used to has setup defaults for missing variables (e.g. for "$chart_name", "event_script" or "canvas_style").

Now that you have learnt what rgraph chart-scripts are and how to use templates, you may want to know how to use them on your website.