Assigning the Result of a Single Item

It is also possible to retrieve the result of a Plotalot plugin call in PHP code in an article. When Joomla renders an article, any plugins replace their calling text with their output text. For charts, the output text is the HTML <div> element that the chart will be drawn in. For Plotalot tables, it's the <table> HTML. You are unlikely to want to manipulate either of those things in PHP in an article. But for a single item, the result is the output of the database query defined for the single item, and in some cases it can be useful to manipulate this within the article.

The trick here is to ensure that the Plotalot plugin values are resolved before the PHP code in the article is executed. You can't do that with Sourcerer because it is a System Plugin, but you can do it with DirectPHP, which is a Content Plugin. You can use the ordering column of the Joomla Plugin Manager to ensure that Plotalot runs before DirectPHP.

In the following example, DirectPHP will not "see" the {plotalot ...} calls because they will have been resolved and replaced with their result values before DirectPHP is called. So in the following example, DirectPHP will run with the output values of the two Plotalot calls, and will execute the PHP code that adds them together and echoes the result:

<?php
$value1 = {plotalot id="1"};
$value2 = {plotalot id="2"};
$value3 = $value1 + $value2;
echo "Result is $value3";
?>