ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Getting graph as image for HTML output (PHP)
Posted by Assylbetti on Apr-30-2012 19:34
Hello everyone. I just started using this library and i like it. But i can't figure out how to embed the graph into HTML.
Help says: use it like this

<HTML>
<BODY>

<h1>Hello World!</h1>
<p>Hi, this is my first web page with ChartDirector charts.</p>

<IMG SRC="http://aaa.bbb.ccc.ddd/ChartDirector/phpdemo/simplebar.php">

More HTML elements ......

</BODY>
</HTML>

But how am i suppose to send the data arrays into sidebar.php???

  Re: Getting graph as image for HTML output (PHP)
Posted by Peter Kwan on May-01-2012 00:16
Hi Assylbetti,

The charting script can obtain the data just like any other PHP script. (How do you send data to your other PHP scripts?)

For example, if the data come from a database, in "simplebar.php", you can read the data from the database or the text file and use the data to plot a chart.

If you need to send some parameters to a charting PHP script, you can send them as query parameters, or as session variables, etc, just like how you would send parameters to other PHP scripts. For example, "simplebar.php?selection=aaa" or "simplebar.php?data=12,4,51,3,4".

There are some examples in the "Using Data Sources with ChartDirector" section of the ChartDirector documentation that demonstates accepting input from the user, using the input to query a database to obtain the data, and then using the data to plot the chart. You may use them as a reference.

Hope this can help.

Regards
Peter Kwan

  Re: Getting graph as image for HTML output (PHP)
Posted by Assylbetti on May-01-2012 14:22
I see that i can pass the parameters through the query, but i have big arrays and i just physically can't pass everything in query. I have a table in my web page, which is being created dynamically from DB depending on 5 parameters that user choose, and i want to draw a chart, but i can't pass everything!!! The arrays are too big!
Can you library for charts create and save the chart as image and then return just a full path to the image? I think that would be great!

  Re: Getting graph as image for HTML output (PHP)
Posted by Assylbetti on May-01-2012 14:29
How can i pass that sort of parameters in a query? Are you kidding me?

$data0 = array(42, 49, 33, 38, 51, 46, 29, 41, 44, 57, 59, 52, 37, 34, 51, 56, 56, 60, 70, 76, 63, 67, 75, 64, 51);
$data1 = array(50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 98);
$data2 = array(36, 28, 25, 33, 38, 20, 22, 30, 25, 33, 30, 24, 28, 15, 21, 26, 46, 42, 48, 45, 43, 52, 64, 60, 70);

$labels = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24");

$legendObj = $c->addLegend(50, 30, false, "arialbd.ttf", 9); $legendObj->setBackground(Transparent);
$textBoxObj = $c->addTitle("Application Server Throughput", "timesbi.ttf", 15); $textBoxObj->setBackground(0xccccff, 0x000000, glassEffect());
$c->yAxis->setTitle("MBytes per hour");
$c->xAxis->setLabelStep(3);
# Add a title to the x axis
$c->xAxis->setTitle("Jun 12, 2006");
# Add a line layer to the chart
$layer = $c->addLineLayer2();
# Set the default line width to 2 pixels
$layer->setLineWidth(2);
# Add the three data sets to the line layer. For demo purpose, we use a dash line # color for the last line
$layer->addDataSet($data0, 0xff0000, "Server #1");
$layer->addDataSet($data1, 0x008800, "Server #2");
$layer->addDataSet($data2, $c->dashLineColor(0x3333ff, DashLine), "Server #3");
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));


Ha-a-a? I i just cant send another query to DB because the data is already in my hands, in the table that i am showing to the user. I can't send another (THE SAME) query to get THE SAME data for the graph - that would double the amount of queries!

  Re: Getting graph as image for HTML output (PHP)
Posted by Peter Kwan on May-01-2012 23:38
Hi Assylbetti,

If you have one script (the script that outputs HTML), and it has already queried the database and obtain the data, and you would like to use the same data in the chart but without querying the database in the charting script again, the followings are some options:

(a) Create the chart in the same script that outputs HTML, then save the chart as an image file on the hard disk (using BaseChart.makeChart), or save the chart as a session variable (use BaseChart.makeSession). Then in the HTML, you may include an <IMG> tag that points to the image file or points to the "getchart.php" script that can retrieve the image from the session variable.

In the "Database Clickable Chart" sample code included in ChartDirector (you may look up "Database Clickable Chart" from the ChartDirector documentation index), there is an example that does exactly the above. The data are retrieved in the script that outputs HTML, the chart is created in the same script and saved as a session variable using BaseChart.makeSession, and getchart.php is used in the <IMG> tag to retreive the chart. May be you can use it as a reference.

(b) Save the data as session variables. Then in the charting script, you can retrieve the data from the session variables. (In other words, instead of passing data by query parameters, you may pass data by session variables.)

Hope this can help.

Regards
Peter Kwan