Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By cosyxu
#825203
Hi Amo,

Just wondering if it is possible to generate a bar chart in the trigger and then send it to someone via email?

For example, when I complete a dyanform, can I use a trigger to generate a bar chart based on the data I entered, and then send this bar chart as an image to myself via an email.

Is this possible?

Thanks,
Yuan
By cosyxu
#825279
amosbatto wrote: Tue Jul 02, 2019 2:04 am Make a trigger with code from this tutorial:
https://linuxhint.com/php-server-side-charts-tutorial/

You need to save the output of $chart->createGraph() into a case variable like this:
Code: Select all
ob_start();
$chart->createGraph();
@@barChart = ob_get_clean(); 
Then in your email template, add the following code:
@#barChart
Hi Amo,

I create a trigger like this and put it before the assignment
Code: Select all
require_once('/phpgraphlib/phpgraphlib.php');

$chart = new PHPGraphLib(600,450);
$data = array(100, 500, 250, 900, 750, 230, 159, 820,645,129,923,312);
$chart->addData($data);
$chart->setTitle('Monthly Sales Report');
$chart->setGradient('blue', 'green');
$chart->createGraph();


ob_start();
@@barChart = ob_get_clean(); 
I also downloaded the lib file and store in D:/phpgraphlib/phpgraphlib.php (D:/ProcessMaker)

But it doesn't work. Can you please provide me more information or guidance?

Thanks,
Yuan
User avatar
By amosbatto
#825280
After you downloaded phpgraphlib/phpgraphlib.php, where did you place the file on your server ?

Then you have to import it correctly into your trigger. For example if you placed the file at:
/opt/processmaker/phpgraphlib/phpgraphlib.php

Then your trigger should start with:
require_once('/opt/processmaker/phpgraphlib/phpgraphlib.php');


You didn't include createGraph() inside the buffer, so your buffer is empty. You have to do it this way:
Code: Select all
ob_start();
$chart->createGraph();
@@barChart = ob_get_clean(); 
By cosyxu
#825284
amosbatto wrote: Thu Jul 04, 2019 10:48 pm After you downloaded phpgraphlib/phpgraphlib.php, where did you place the file on your server ?

Then you have to import it correctly into your trigger. For example if you placed the file at:
/opt/processmaker/phpgraphlib/phpgraphlib.php

Then your trigger should start with:
require_once('/opt/processmaker/phpgraphlib/phpgraphlib.php');


You didn't include createGraph() inside the buffer, so your buffer is empty. You have to do it this way:
Code: Select all
ob_start();
$chart->createGraph();
@@barChart = ob_get_clean(); 
Hi Amo,

After I downloaded the file, I put it under the D:\phpgraphlib, same as processmaker, D:\processmaker.

I have update my code like this but still not work.
Code: Select all
require_once("D:/phpgraphlib/phpgraphlib.php");

$chart_test = new PHPGraphLib(600,450);
$data_test = array(100, 500, 250, 900, 750, 230, 159, 820,645,129,923,312);
$chart_test->addData_test($data_test);
$chart_test->setTitle('Monthly Sales Report');
$chart_test->setGradient('blue', 'green');

ob_start();
$chart_test->createGraph();
@@barChart = ob_get_clean(); 

Any ideas?

Thanks,

Yuan
User avatar
By amosbatto
#825322
The problem is that phpgraphlib is generating a PNG file, but that PNG can't be saved inside a ProcessMaker case variable. PHP has no problem storing binary contents inside a variable, but ProcessMaker can't save that as a case variable in the database.

The solution is to either switch to a different PHP library which can generate a chart using <canvas> in HTML5 or to create a temporary PNG file on the ProcessMaker server and add that file as an attachment to the email (which means that the chart can't be in the middle of the text of your email). A <canvas> in HTML5 can be stored as plain text in a ProcessMaker case variable, but it can be hard to copy and paste a <canvas> from an email into another document. You might have to take a screen shot and paste the screenshot if your users want to cut and paste the bar chart.

Which solution do you prefer?
By cosyxu
#825323
Hi Amo,

Thanks very much for the two solutions.

I think we may prefer the second solution which is to generate a temporary png on the server, and then attached to the emails. By doing this, like you said, our users can easily copy and paste the diagram, and as the attachment, I don't need to worry about the layout the image on the email.

So can you please provide more details on this?

Thanks and regards,
Yuan

AI bot development involves creating intelligent b[…]

AI bot development encompasses creating intelligen[…]

A stake clone script is a pre-coded solution desig[…]

The bet365 clone script offers a ready-made soluti[…]