pChart 2.x forum
http://wiki.pchart.net/forum/

return pixel coordinate offsets for any chart (for html map)
http://wiki.pchart.net/forum/viewtopic.php?f=3&t=34
Page 1 of 1

Author:  mykchan [ Fri Dec 17, 2010 4:23 am ]
Post subject:  return pixel coordinate offsets for any chart (for html map)

hi,

i have a feature request but im not sure how possible it would be to implement.

can pChart return the coordinates (pixel offsets - top right bottom and left) for each element on a chart, to construct a html map element with appropriate area coordinates?

this would enable tooltips for individual bars, or slices of a pie chart, or lines of a line chart, etc.

in the case of overlaid datasets and filled-type charts, it could be up to the developer to control how the map works with conflicting area tags...

Author:  mykchan [ Fri Dec 17, 2010 5:02 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

Bar Chart Only

okay, this was extraordinarily easy to do - i love pChart! JD, youve coded it very well for people who want to explore and extend it :D

the changes (to pChart2.0.7) i had to make to accomplish this:

pImage.class: line 63:
Code:
   /* Pixel Offset Coordinate Map */
   var $PixelOffsetCoordinates = NULL;         // Populated in Drawing functions, accessable to instantialiser


pDraw.class: line 3056:
Code:
   $this->PixelOffsetCoordinates[$SerieName]=array();



pDraw.class: line 3056:
Code:
   $this->PixelOffsetCoordinates[$SerieName][$Key]=array(array($X+$XOffset+$XSpace,$Y2),array($X+$XOffset+$XSize-$XSpace,$Y1));


then in your chart-generating php file:
Code:
if (isset($_GET['output'])) {
   $chart->Stroke();
   exit;
} else {
   $map="<map name='report_map>";
   foreach ($graph_data->Data['Series'] as $SeriesName => $Serie) {
      if ($SeriesName==$graph_data->Data['Abscissa']) continue;
      foreach ($this->chart->PixelOffsetCoordinates[$SeriesName] as $key=>$pos) {
         $map.="<area shape='rect' coords='".ceil($pos[0][0]).",".ceil($pos[0][1]).",".ceil($pos[1][0]).",".ceil($pos[1][1])."' title='".$SeriesName." ".$graph_data->Data['Series'][$graph_data->Data['Abscissa']]['Data'][$key].": ".number_format($graph_data->Data['Series'][$SeriesName]['Data'][$key])."' />";
      }
   }
   $map.="</map>";
   return "<img src='".$chart_image_url."&output' usemap='#report_map' />".$map;
}

Author:  jean-damien [ Fri Dec 17, 2010 9:29 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

This will be added to all charting function. I plan to re-build an interface for HTML maps like in the v1 with some JS client side extensions.

Author:  mykchan [ Mon Dec 20, 2010 4:59 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

until JD builds this properly into pChart, i have created extended functionality for bar, line and pie charts.

ive posted a how-to for bar charts above; if anyone wants pie charts or line charts too, let me know and i'll write about them here too.

Author:  mice32 [ Mon Dec 20, 2010 6:11 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

> until JD builds this properly into pChart, i have created extended functionality for bar, line and pie charts.
Hmm... Interesting... I think, you could post your tutorial in viewforum.php?f=4.

Author:  sbekker [ Mon Apr 18, 2011 11:22 pm ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

Hi JD,

When will you be adding hover tooltips to the graphs? My client likes your charts but needs this functionality URGENTLY as usual. :D

Author:  jean-damien [ Tue Apr 19, 2011 7:30 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

Implementation is almost done and will be release in the next minor ;o)

JD.

Author:  sbekker [ Tue Apr 19, 2011 11:24 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

Darn. This clients wants it this week. Oh well just have to use google charts for now.. :-(

Author:  jean-damien [ Tue Apr 19, 2011 12:10 pm ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

It's not that easy ;o) it involves both PHP, JavaScript and HTML parts.

Author:  jean-damien [ Fri Aug 05, 2011 8:44 am ]
Post subject:  Re: return pixel coordinate offsets for any chart (for html

The 2.1.2 version has been published yesterday implementing this feature and is now available for download at http://www.pchart.net/download.

JD.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/