Can somebody explain to me how to configure a zendframework project with PCharts?I need to show data from my database in graph form. If possible please send me an example code of how to put the pieces together. Thank you
3 Answers
Call your pichartcreateAction in src attribute of an image of your .phtml file, like
< img src="YOUR_SITE_PATH/Controller/pichartcreateAction" > In you main page phtml file
Now in pichartcreateAction() do the same as 'Mario' said.

- 136
- 1
- 7
I must say that this is not a different answer than that of Mario's but for me it was better solution with pChart in Path. As follows:
//public/index.php
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../library/pChart/class'),
...
get_include_path(),
)));
Render the Chart and return image name and path whom you'll need to use in the view, and you're all set. Please ask, if in doubt.
-
1That definitely a little nicer than having the includes in the action. – Mario Jan 31 '14 at 08:07
There may be a better way to do this, but since no one has answered here's a fairly simple way to do it.
Start by placing pChart in your library directory (myapp/library/pChart).
Next create an action for rendering the image (yes, your chart will require it's own action as you need to disable layouts and views, and set the header.)
Note: The following code will go into your action and I have only included the parts relevant to Zend Framework integration.
Disable layouts and views:
$this->_helper->getHelper("layout")->disableLayout();
$this->_helper->viewRenderer->setNoRender();
Include pChart:
include(APPLICATION_PATH."/../library/pChart/class/pData.class.php");
include(APPLICATION_PATH."/../library/pChart/class/pDraw.class.php");
include(APPLICATION_PATH."/../library/pChart/class/pImage.class.php");
Now start building your chart (pChart code excluded for clarity):
{... pChart code ...}
When specifying fonts use the full path:
$myPicture->setFontProperties(array(
"R"=>0,"G"=>0,"B"=>0,
"FontName"=>APPLICATION_PATH."/../library/pChart/fonts/pf_arma_five.ttf",
"FontSize"=>12
));
Finish your chart code (pChart code excluded for clarity):
{... pChart code ...}
Finally set the content-type to image/png and render the image:
header('Content-type: image/png');
$myPicture->stroke();

- 1,999
- 2
- 15
- 28