Page 1 of 2
generating a php graph
Posted: Sun Jun 07, 2009 12:51 pm
by lafayette
Hi all, I downloaded a class to build php graphs (actually I tried with 2, postgraph and phpmygraph): both works in CMSms if I put in the html of a page something like
Code: Select all
<img src="file_with_graph_gen.php" />
while if I put the content of that php file in an UDT, and invoke it in the src attribute of img tag, I only get plain and raw text of the png image.
Any ideas? Should I stick with the graph code in an external file, not manageable directly by cmsms?
Re: generating a php graph
Posted: Tue Jun 09, 2009 7:52 pm
by lafayette
any idea? or at least, is this the right section for that?
Re: generating a php graph
Posted: Wed Jun 10, 2009 8:41 am
by alby
lafayette wrote:
while if I put the content of that php file in an UDT, and invoke it in the src attribute of img tag, I only get plain and raw text of the png image.
What code you put in UDT?
Alby
Re: generating a php graph
Posted: Wed Jun 10, 2009 10:52 am
by Peciura
Hi i checked phpMyGraph4.0.php
it works if you put something like
but it doesn't if you copy - paste "phpMyGraph4.0.php" code to UDT (let say 'phpMyGraph'). Your UDT creates image data stream, but omits headers like
Code: Select all
header ('Content-type: image/png');
Code: Select all
header ('Content-type: image/png');
$graph->parseVerticalColumnGraph($data);
Doesn't work for me either.
And i can't figure it out how to send it properely.
Still it is posible to make it work from UDT
Basic idea is to create real image , save it to disc and return image path to tag.
You will need 2 parameters in your UDT, one parameters for graph data array and other optional for image configuration array ('file-name', 'width', 'height', 'transparent-background','font-size', ....).
Re: generating a php graph
Posted: Wed Jun 10, 2009 11:05 am
by lafayette
I'll try to best answer..
in UDT i put code for generating graph (without ) that includes phpmygraph file. the code is correct since specifying the separate file in img src works greatly.
Peciura: do you think that I should make phpmygraph output an image file and then embed it in html? it seems the correct way, but can't get phpmygraph write on a file..
Re: generating a php graph
Posted: Thu Jun 11, 2009 11:57 am
by Peciura
I think we will endup with plugin.
Just updated file.
Tag returns path to graph image. All available params (exept data array) are listed at the top of file ('-' must be replaced with '_'). Default is vertical column graph.
If you
submit data array it will create graph image,
don't submit data array it will return existing graph image path.
If image path is missing it will use default img.
If image is missing on disk exeption will ocure;
For testing purposes use something like this in your page
Code: Select all
{php}
$this->assign('data_array', array(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>100)); {/php}
<img src="{phpMyGraph file_name='uploads/testas.png' data=$data_array graph_background_color='FF0000'}" />
P.S Help function is now included.
Re: generating a php graph
Posted: Thu Jun 11, 2009 8:54 pm
by lafayette
I pasted it in a UDT that I after invoked on a page...seems that the file simply can't be created, or I can not found it
where should I look for it?
or your file wasn't intended to be used as UDT?
Re: generating a php graph
Posted: Thu Jun 11, 2009 8:58 pm
by alby
lafayette wrote:
or your file wasn't intended to be used as UDT?
No, is same but it's a tag
save file in your PC, rename from .txt to .php and put in
plugins folder
Alby
Re: generating a php graph
Posted: Fri Oct 09, 2009 9:30 am
by lafayette
Sorry if i re-up this old post, but it's natural prosecution of this
I'm trying to use plugin supplied by Peciura, however it only works with default configuration. I'm struggling to edit the source php file to let him accept a configuration array passed on invocation (something like {phpMyGraph data=$data_array cfg=$cfg_array}) but can't manage to get it working.
P.S. another little trouble: even if I paste php code in plaintext, tinymce at next editing of the page converts all the ">" and "<" into html entities, messing up the php code. any way to avoid this?
Re: generating a php graph
Posted: Fri Oct 09, 2009 11:47 am
by Peciura
Hi,
Param "cfg" is not supported.
At the time i posted tag to forum project was not registered, so basic help is at the top of the file and at
http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Tags/php_My_Graph
Anyway discussion is always welcome.
Here is complete example (with default values) of tag usage
Code: Select all
{php}
$this->assign("data_array", array(
"Mon"=>10,
"Tue"=>20,
"Wed"=>30,
"Thu"=>100,
"Fri"=>20,
"Sat"=>10,
"Sun"=>33));
{/php}
<img src='{phpMyGraph file_name="uploads/test.png" data=$data_array
type = "HorizontalColumnGraph"
file_name = "test_graph.png"
title = "test"
width = 200
height = 200
font_size = 2
background_color = "FFFFFF"
graph_background_color = "E2E1E2"
font_color = "006699"
column_font_color_q1 = "000000"
column_font_color_q2 = "000000"
border_color = "006699"
column_color = "0099CC"
column_shadow_color = "006699"
min_col_width = "32"
background_color_alpha = 0
graph_background_color_alpha = 0
font_color_alpha = 0
column_font_color_q1_alpha = 0
column_font_color_q2_alpha = 0
border_color_alpha = 0
column_color_alpha = 0
column_shadow_color_alpha = 0
transparent_background = 0
random_column_color = 0
disable_legenda = 0
disable_values = 0
}' />
Re: generating a php graph
Posted: Mon Oct 04, 2010 6:26 pm
by rica_carv
Hi...
I'm trying to use this module, but it doesn't work....
I've try'ed the way it was stated here, but it just messes my css....
And no graphic....
Re: generating a php graph
Posted: Mon Oct 04, 2010 7:05 pm
by Peciura
Just tried it on CMSms 1.8.2 - it worked.
Code: Select all
{php}
$this->assign('data_array', array(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>150));
{/php}
<img src="{phpMyGraph file_name='uploads/test.png' data=$data_array}" />
Post your template to forum.
Re: generating a php graph
Posted: Mon Oct 04, 2010 9:46 pm
by NaN
rica_carv wrote:
I've try'ed the way it was stated here, but it just messes my css....
Take a look in the HTML source of your browser.
I bet the head section is missed and so no stylesheets can be loaded.
This is often caused by a fatal php error or an exit command of a module or plugin that is placed in the body (body is processed before the head so modules can apply stuff they need to the head section before page is actually rendered).
To use {php} ... {/php} you need to set $config['use_smarty_php_tags'] = true; in your config.php.
Re: generating a php graph
Posted: Wed Oct 06, 2010 11:44 am
by rica_carv
Peciura wrote:
Just tried it on CMSms 1.8.2 - it worked.
Code: Select all
{php}
$this->assign('data_array', array(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>150));
{/php}
<img src="{phpMyGraph file_name='uploads/test.png' data=$data_array}" />
Post your template to forum.
I'm not using it inside the template, i'm trying to use it inside the page content....
NaN wrote:
rica_carv wrote:
I've try'ed the way it was stated here, but it just messes my css....
...To use {php} ... {/php} you need to set $config['use_smarty_php_tags'] = true; in your config.php.
But that is not recomended, right?
It just leaves the gate open to insert php code who edits or inserts content on the site, right?
I've try'ed to put the php code inside a custom tag, and call it from the content area...
It doesn't work neither....
Re: generating a php graph
Posted: Wed Oct 06, 2010 3:40 pm
by Peciura
I'm not using it inside the template, i'm trying to use it inside the page content....
you can use it in page content or template - does not really matter.
{php} and {/php} were used in example just to generate array. It show that tag has to be supplied with associated array.
array('column_name' => 'value',...)
You could do other way if you like
{assign var='keys' value=','|explode:'Mon,Tue,Wed,Thu,Fri,Sat,Sun'}
{assign var='values' value=','|explode:'10,20,30,100,20,10,150'}
{assign var='data_array' value=$keys|@array_combine:$values}
or create UDT that assign values to variable {$
data_array}. It is close to scenario when you retrieve data from DB or transform some sort of multidimensional array (or object) to associated array
$smarty = cmsms()->GetSmarty(); // cms_utils :: get_smarty();
$smarty->assign('data_array', array(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>69,
'Fri'=>20,
'Sat'=>10,
'Sun'=>150));