Notice: Undefined variable: wsnum in /www/zendcore/htdocs/examples/ssgraph.php on line 29
Single Series SmartChart PHP

Single Series SmartChart PHP

Description:   This example demonstrates how to build a Single Series SmartChart graph in WebSmart PHP.

Follow the instructions below to create a program similar to this one:
  1. Start by creating a new program using the A Simple Page template, from any of the PHP template families.


  2. Near the top of your code, immediately below the 'require' statement, add the following lines to create the global variables you'll use:
    //globalize the variables
    global  $selstring, $graphdata, $numdecimals, $decFormat, $numPrefix, $numSuffix;
    global  $formatNum, $altGridColors, $xName, $yName, $grCaption, $grSubCaption;
    global  $yAxisMin, $showGrValues, $showGrNames, $grWidth, $grHeight;
    
                          
  3. Below the lines you just added, copy in these graph settings:
    //Set Graph properties. You can find more properties and their settings at 
    //http://www.excelsystems.com/smartcharts/helpdocs/Index.html.  Click on Single Series Chart XML
    //then 3D Column Chart.
    $numdecimals = "0";
    $decFormat = ".";
    $numPrefix = "";
    $numSuffix = " Units";
    $formatNum = "0";
    $altGridColors = "0";
    $xName = "";
    $yName = "Inventory";
    $grCaption = "Inventory On Hand"; 
    $grSubCaption = "";
    
    $yAxisMin = "0";
    $showGrValues = "1";
    $showGrNames = "1";	
    $grWidth = "700";
    $grHeight = "400";
                          


  4. Now, immediately below the code above, add this PHP code to set up your database connection:
    // DB Connection code
    $options = array('i5_naming' => DB2_I5_NAMING_ON);
    
    global $db2conn;
    $db2conn = xl_db2_connect(Array);
    
    if(!$db2conn)
    {
    	die('Could not connect to database: ' . db2_conn_error());
    }
                          

  5. Set up a Switch statement to call the different functions in your program. Copy this into the PHP Source code below the database connection
    // run the specified task
    switch($pf_task)
    {
    	case 'default':
    	generic();
    	break;
    	
    	// Record display option
    	case 'RUN_REPORT':
    	buildgraph();
    	break;    
    	
    }
                          

  6. At the bottom of your PHP code, add this new function:
    function generic()
    {	
    	wrtseg('MainSeg');	
    }
                          

  7. Now add the buildgraph() function to your program, to generate the graph:
    function buildgraph()
    {
    	
    	// Make all global variables available here
    	foreach($GLOBALS as $arraykey=>$arrayvalue) 
    	{
    		if($arraykey[0]!='_' && $arraykey != 'GLOBALS')
    			global $$arraykey;
    	}
    	
    	$graphdata = "";
    	
    //Get Level Break category names and values for graph	
    $selstring = "select IMCAT,sum(IMQTONHD) AS IMQTONHD from xl_webdemo/mu_itmf group by IMCAT" ;
    	
    	//test the resource statement
    	if (!($stmt = db2_exec($db2conn, $selstring))) 
    	{
    		echo "Error ".db2_stmt_error() .":".db2_stmt_errormsg(). ""; 
    		die;
    	}
    	
    	// While SQL retrieves records assign the names and values
    	while ($row = db2_fetch_assoc($stmt))
    	{
    	 // Get the fields 
    	 $IMCAT = $row["IMCAT"];
    	 $IMQTONHD = $row["IMQTONHD"];
    	 $graphdata = $graphdata ."<set name='". trim($IMCAT); 
    	 $graphdata = $graphdata ."' value='" .$IMQTONHD . "'color='004080'/>\r\n";		
    	}
    	
    	//close the connection
    	db2_close($db2conn);
    	
    	//output the graph	
    	wrtseg('GraphSeg');	
    }
                          

  8. From the Attributes/Segments menu option, create a new HTML segment named GraphSeg.


  9. Then add this code to your new HTML segment:
    <graph
     xaxisname="$xname"
     yaxisname="$yname"
     caption="$grcaption"
     subcaption="$grsubcaption"
     showValues="1"
     showNames="1"
     yAxisMinValue="$yAxisMin"
     showAlternateHGridColor="$altgridcolors"
     decimalPrecision="$numdecimals"
     numberPrefix="$numprefix"
     numberSuffix="$numsuffix"
     decimalSeparator="$decformat"
     formatNumberScale="$formatnum">
     
     $graphdata
     </graph>
                          

  10. Now go to the HTML segment MainSeg and add this code between the <head> and </head> tags:
    <script language="JavaScript" src="/websmart/clover/v1.5/javascript/esdiapi.js"></script>
                           
    The clover directory this references is also installed with WebSmart.


  11. Finally, replace everything in the body of your HTML page (the content between the<body> and </body> tags) with the following Flash Object:
    <div id="main" align="center">
    <script type="text/javascript">
    var fo = new FlashObject("/websmart/smartcharts/v1/SC_2_3_Column3D.swf",
                             "movie", "$pf_scriptname", "700", "400", "6", "#FFFFFF");
    fo.write("main");
    </script>
    </div>
    
                          

  12. Compile and run your program

Program Definition:   ssgraph.phw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don't Know

Enter additional comments below.   If you want to hear back from us, include your contact information.