Is it possible to use image maps and cache the charts at the same time? When I enable caching, the image maps are no longer created. I need to have the image maps so the value is shown when i mouse over it, but I would like to be able to cache the charts to significantly reduce my cpu load. I haven't been able to find info about this anywhere and the pChart forums are a mess.
Asked
Active
Viewed 420 times
2 Answers
0
With the current version (2.1.3) this is not possible. The image map is only created when pChart actually draws the image i.e. later when you grab the image from cache the image map is not available.
To get around it you can cache the image maps yourself. Going off the example on http://wiki.pchart.net/doc.imagemaps.fundamentals.html you could do something along these lines
//initialise the map
$myPicture->initialiseImageMap("ImageMapBarChart", IMAGE_MAP_STORAGE_FILE, "BarChart", "../tmp");
//draw the chart
$Settings = array("RecordImageMap" => TRUE);
$myPicture->drawBarChart($Settings);
//the image map is ready for you here
//so before you output the chart get the map with dumpImageMap() and copy it to YOUR OWN CACHE
$myPicture->dumpImageMap("ImageMapBarChart", IMAGE_MAP_STORAGE_FILE, "BarChart", "../tmp");
I know this is an old question but I hope this helps.

user2910443
- 111
- 3
0
I was able to get this to work using the following code. I apologize for the formatting, limitation of the forum. I also had to modify pImage.class to not delete the tmp files, so they are saved for cached images.
if ( $myCache->isInCache($ChartHash)) {
/* Retrieve the image map */
if (isset($_GET["ImageMap"]) || isset($_POST["ImageMap"])) {
$StorageFolder = PCHART_PATH . "/cache/imageMap";
$UniqueID = "AreaChart".$ChartHash;
if (file_exists($StorageFolder."/".$UniqueID.".map")) {
$Handle = @fopen($StorageFolder."/".$UniqueID.".map", "r");
if ($Handle) { while (($Buffer = fgets($Handle, 4096)) !== false) { echo $Buffer; } }
fclose($Handle);
}
}
/* Output cached image */
$myCache->strokeFromCache($ChartHash,"pictures/drawAreaChart.".$ChartHash.".png");
}