View unanswered posts | View active topics It is currently Sun Apr 28, 2024 7:06 pm



Reply to topic  [ 2 posts ] 
NEWBIE - Need assistance 
Author Message
pChart user
pChart user

Joined: Mon Jun 04, 2012 5:41 pm
Posts: 6
Post NEWBIE - Need assistance
I'm new to Pchart, and trying to learn quickly as (of course) my employers have a project that needs to be done immediately. I'm trying to create a BI page of sorts, that pulls real-time information from our IBM i system. I have a PHP application which requests a product ID, pulling the data in, and displays a bill-of-material listing, an image of our product, sales history and forecasting. I'd like to display the history and forecast information using pchart, but I don't understand how to display it in my current PHP document. I can display it successfully by using a link to it's own PHP code (passing the product ID through _GET), but I want it displayed automatically on the same page as the bill-of-material and product image.

How do I do this? :( ((Really wish there was a better tutorial for this product, it seems like a powerful tool!))


Mon Jun 04, 2012 5:50 pm
Profile
Experienced pChart user
Experienced pChart user

Joined: Tue Aug 02, 2011 11:49 pm
Posts: 34
Post 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 file
don'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


Tue Jun 05, 2012 11:32 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron