generating a php graph

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
User avatar
lafayette
New Member
New Member
Posts: 8
Joined: Sun Jun 07, 2009 12:47 pm

generating a php graph

Post 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?
User avatar
lafayette
New Member
New Member
Posts: 8
Joined: Sun Jun 07, 2009 12:47 pm

Re: generating a php graph

Post by lafayette »

any idea? or at least, is this the right section for that?
alby

Re: generating a php graph

Post 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
Peciura

Re: generating a php graph

Post by Peciura »

Hi i checked phpMyGraph4.0.php
it works if you put something like

Code: Select all

<img src="phpMyGraph4.0.php" />
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', ....).
Last edited by Peciura on Wed Jun 10, 2009 11:00 am, edited 1 time in total.
User avatar
lafayette
New Member
New Member
Posts: 8
Joined: Sun Jun 07, 2009 12:47 pm

Re: generating a php graph

Post 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..
Peciura

Re: generating a php graph

Post 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.
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

Last edited by Peciura on Fri Jun 12, 2009 6:22 pm, edited 1 time in total.
User avatar
lafayette
New Member
New Member
Posts: 8
Joined: Sun Jun 07, 2009 12:47 pm

Re: generating a php graph

Post 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?
alby

Re: generating a php graph

Post 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
User avatar
lafayette
New Member
New Member
Posts: 8
Joined: Sun Jun 07, 2009 12:47 pm

Re: generating a php graph

Post 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?
Peciura

Re: generating a php graph

Post 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
}' /> 
rica_carv
Forum Members
Forum Members
Posts: 11
Joined: Fri Oct 01, 2010 4:30 pm

Re: generating a php graph

Post 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....
Peciura

Re: generating a php graph

Post 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.
NaN

Re: generating a php graph

Post 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.
rica_carv
Forum Members
Forum Members
Posts: 11
Joined: Fri Oct 01, 2010 4:30 pm

Re: generating a php graph

Post 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....
Peciura

Re: generating a php graph

Post 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));
Last edited by Peciura on Wed Oct 06, 2010 8:12 pm, edited 1 time in total.
Post Reply

Return to “Modules/Add-Ons”