Re: NEWBIE - Need assistance
the
documentation is not that bad
you should create a directory on the server e.g. 'imgCache'
create one php-file only for rendering the chart itself
(this file contains the complete structure: MyData->addPoints etc.)
the code in it ends with $myPicture->
render($imgPathFile); =>take a look on
Rendering to a flat filedon't use fixed data in it, just variables and arrays for all necessary input
and put a "created" - timestamp into the chart e.g. in a footer
in your existing php-file which grabs the data out of your system:
- first of all receive the needed data
- process the data however you need
- include pChart classes "pData.class.php", "pDraw.class.php" and "pImage.class.php"
- put the preprocessed data and additional data for the charts into variables and arrays *1)
- perhaps you want to replace zero-values with the pChart-VOID-constant
Code:
function setVOID(&$zeroitem) { // reference to original value of array-item
if ($zeroitem == 0) {
$zeroitem = VOID; // "pData.class.php" (defines VOID) must be included already before running the function
}
}
for ($i = 0; $i < count($yourDataSeriesArray); $i++) {
setVOID($yourDataSeriesArray[$i]);
}
then you can render the charts (so much as you need, all with different data, but the same structure und design)
on the left the variables and arrays used before in your chart-rendering.php
on the right the data [as in *1)] to put into charts
Code:
/* render the charts */
// No.1
$myTitle = $device1.$titletext1.$yourWhatever1; // your turn to fill in data
$dataseries1 = $yourProcessedData1;
$dataseries2 = $yourProcessedData2;
$src1 = '[server path to]/imgCache/chart1.png';
$imgPathFile = $src1; // the variable in chart-rendering.php from above
*2) [perhaps you want to archive old image first (see below)]
include 'chart-rendering.php';
// No.2
$myTitle = $device2.$titletext2.$yourWhatever2; // your turn to fill in data
$dataseries1 = $yourProcessedData3;
$dataseries2 = $yourProcessedData4;
$src2 = '[server path to]/imgCache/chart2.png';
$imgPathFile = $src2; // the variable in chart-rendering.php from above
*2) [perhaps you want to archive old image first (see below)]
include 'chart-rendering.php';
// No.3
$myTitle = $device3.$titletext3.$yourWhatever3; // your turn to fill in data
$dataseries1 = $yourProcessedData5;
$dataseries2 = $yourProcessedData6;
$src3 = '[server path to]/imgCache/chart3.png';
$imgPathFile = $src3; // the variable in chart-rendering.php from above
*2) [perhaps you want to archive old image first (see below)]
include 'chart-rendering.php';
finally you echo the output as usual and put some images into your HTML
Code:
echo '<img id="chart1" src="'.$src1.'" alt="chart1" border="0">';
echo '<img id="chart2" src="'.$src2.'" alt="chart2" border="0">';
echo '<img id="chart3" src="'.$src3.'" alt="chart3" border="0">';
et voila job done
make sure that your browser doesn't present cached images (browser settings) and via
Code:
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate, no-store">
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
*2) if you want to archive old chart-images just rename the existing png-files before rendering new charts
(make sure that there are already some trash-png's with the correct filenames before running the script for the first time to avoid errors)
observe the server space! each time you refresh the browser a new copy of the png's will be created
Code:
rename($src1, '[server path to]/imgCache/archived/'.date('ymd').'_'.date('H-i-s').'_chart1.png');
rename($src2, '[server path to]/imgCache/archived/'.date('ymd').'_'.date('H-i-s').'_chart2.png');
rename($src3, '[server path to]/imgCache/archived/'.date('ymd').'_'.date('H-i-s').'_chart3.png');
or have a deeper look on
pCache.class.php