Login Register Wishes Forum About
Language Reference » Image Maps » Fundamentals
Help topics
Latest updates
4640d  replaceImageMapTitle
4640d  replaceImageMapValues
4640d  createFunctionSerie
4640d  setAbsicssaPosition
4640d  negateValues
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
Image maps

Image maps support has been introduced in the 2.1.2 version of the pChart library. Image maps allows you to create client side managed zones based on the contents of your charts. This process is completely dynamic and integrated with the pChart core functions. The image maps sent to the browser can be either managed with standard HTML operation or through a provided javascript that adds some extra visual functions (smooth move of the DIV tag, transparency, ..)

You‘ll find a live example of this feature in the examples/imageMap/ folder of the pChart library.

Server side philosophy

You must first decide where will be stored the imagemap coordinates. As of today there are two ways : in the user session or in a flat temporary file. The session is the most esthetic way but it will only work if you have one single chart using imagemap on your web page. The flat file solution will work in all cases but you must allow your webserver to create temporary files (in the folder you choose).
To initialise the image map collection you have to call the initialiseImageMap() function :


The image maps coordinates are computed while calling a charting function (eg: drawBarChart). To enable it, you must set the RecordImageMap parameter to TRUE :

 $Settings = array("RecordImageMap"=>TRUE); 

When the client will request the image map, you‘ll just have to pop it out from the store using the dumpImageMap() function :


Client side philosophy

The client will first render the picture from an <IMG.. tag then a javascript will take over (imagemap.js). This script will check if the picture is rendered checking the img DOM object. When the image is rendered and displayed it will download the image map from the server and apply it over the picture. The only thing to do in your HTML page is to instruct the script which IMG tags must be monitored :
 <script src="imagemap.js" type="text/javascript"></script>

<img src="draw.php" id="testPicture" alt="" class="pChartPicture"/>


You can use the pChartPicture CSS class to remove the border of the picture that will appears when an imagemap is binded to it. just set the "border: 0px" option to this class. pictureMap is an unique identifier that will be used to import the image map coordinates and bind it to your picture.

Script example

 <script src="imagemap.js" type="text/javascript"></script>

<img src="draw.php" id="testPicture" alt="" class="pChartPicture"/>


draw.php (remember to update the PATH accordingly to your system)
 /* Library settings */
 define("CLASS_PATH", "../../../class");
 define("FONT_PATH", "../../../fonts");

 /* pChart library inclusions */

 /* Create and populate the pData object */
 $MyData = new pData();  
 $MyData->addPoints(array(150,220,300,-250,-420,-200,300,200,100),"Server A");
 $MyData->addPoints(array(140,0,340,-300,-320,-300,200,100,50),"Server B");

 /* Create the pChart object */
 $myPicture = new pImage(700,230,$MyData);

 /* Retrieve the image map */
 if (isset($_GET["ImageMap"]) || isset($_POST["ImageMap"]))

 /* Set the image map name */

 /* Turn of Antialiasing */
 $myPicture->Antialias = FALSE;

 /* Draw the background */
 $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);

 /* Overlay with a gradient */
 $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);

 /* Add a border to the picture */

 /* Set the default font */

 /* Define the chart area */

 /* Draw the scale */
 $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);

 /* Write the chart legend */

 /* Turn on shadow computing */ 

 /* Draw the chart */
 $Settings = array("RecordImageMap"=>TRUE);

 /* Render the picture (choose the best way) */
Last updated on 08/04/2011 
by Jean-Damien 
Linked resources
  There is no linked topic yet.
Community comments
  No comments have been posted yet.
© Copyrights
Components used on this web site : Famfamfam icons has been made by Mark James, Rounded corners lite has been coded by Cameron Cooke and Tim Hutchison, SyntaxHighlighter has been written by Alex Gorbatchev. pChart and this web site have been created by Jean-Damien POGOLOTTI. This documentation contains 185 pages and 56 comments. 415 users have registered. This page has been rendered in 0,01 seconds. Wiki revision 1.37.