Jump to content

Using the pChart library with Safari and IE6


radi8

Recommended Posts

I have been playing with pChart library and have been having issues getting it to work with both IE6 and Safari. It appears to work fine with IE7 and above and Firefox, but I would really like to get it to work with IE6 and Safari (iPhone browser).

 

I am not getting any errors when it renders the chart, but am getting a blank image. Does anyone have any experience with this utility?

Link to comment
Share on other sites

Thise sample is designed to pass a few arrays via session variables to the litmChart.php page (pChart rendering processes). You will need to have the pChart classes in order for this to work (notice the include path), and the images will not show up, but everything else should be good.

Here is the main page:

<?php
       ob_start();
        include ('config.inc');
        session_start();
        header("Cache-control: private"); // IE 6 Fix.
        $dodebug=0;
        $hosturl=(substr($_SERVER['HTTP_HOST'],0,9)=='localhost')?"http://".$_SERVER['HTTP_HOST']:$_SESSION['http'].$_SERVER['HTTP_HOST']."/itemCost";
        echo $hosturl."<br>";
        $valid=1;
        /*
        if(!isset($_SESSION['firstload'])){
            echo '<meta http-equiv="refresh" content="2">';
            $_SESSION['firstload']=true;
            $valid=99;
        }
        else{
        */
        if($valid==1){
            $litm='Part Number';
            $aitm='Part Description';
            $branch='PA';
            // build working arrays
            $arr = array(736000,248400,1628400,55200,0,0,0,0,0,0,0,0);
            $arr1 = array(386400,156400,303600,165600,193200,616400,414000,257600,276000,349600,101200,82800);
            $arr2 = array(358800,220800,303600,174800,828000,119600, 92000,542800,717600,303600,257600, 478400);
            //for($i=1;$i<=12;$i++){$arr2[$i]=0;}
            $year=2009; 
            $year1=2008; 
            $year2=2007;
            $months = array();
            $months[1]='Jan';
            $months[2]='Feb';
            $months[3]='Mar';
            $months[4]='Apr';
            $months[5]='May';
            $months[6]='June';
            $months[7]='July';
            $months[8]='Aug';
            $months[9]='Sept';
            $months[10]='Oct';
            $months[11]='Nov';
            $months[12]='Dec';
            $_SESSION['arr']    =$arr;
            $_SESSION['arr1']   =$arr1;
            $_SESSION['arr2']   =$arr2;
            $_SESSION['year']   =$year;
            $_SESSION['year1']  =$year1;
            $_SESSION['year2']  =$year2;
            $_SESSION['months'] =$months;
            $_SESSION['maxval'] =$maxval;
            $_SESSION['litm']   =$litm;
            
            //create the grid data strings
            $rowHead    ="<table width=\"100\" border=\"1px\" align=\"center\"><caption>Item Grid data for $litm, based on Transaction Date</caption>";
            $rowMonth   ="<tr><th scope=\"col\"> </th>";
            $rowDetail ="<tr><th scope=\"row\">".$year."</th>";
            $row1Detail ="<tr><th scope=\"row\">".$year1."</th>";
            $row2Detail ="<tr><th scope=\"row\">".$year2."</th>";
            for($i=1;$i<=12;$i++){
                $rowMonth   .="<th scope=\"col\">".$months[$i]."</th>";
                $rowDetail .="<td>".number_format($arr[$i], 0, '.', ',')."</td>";
                $row1Detail .="<td>".number_format($arr1[$i], 0, '.', ',')."</td>";
                $row2Detail .="<td>".number_format($arr2[$i], 0, '.', ',')."</td>";
            }
            $rowMonth   .="<th scope=\"col\">Total</tr>";
            $rowDetail .="<td>".number_format($Year_ttl, 0, '.', ',')."</td></tr>";
            $row1Detail .="<td>".number_format($Year1_ttl, 0, '.', ',')."</td></tr>";
            $row2Detail .="<td>".number_format($Year2_ttl, 0, '.', ',')."</td></tr>";
            $rowFooter  ="</table>";
            // END DATABASE SECTION AND NSI SPECIFIC SECTION 
        }       
        if($dodebug > 0){
            echo "<pre>";
            if($dodebug==1){
                echo "--> Form data (POST) <-- <br>";
                print_r ($_POST);
            }
            if($dodebug==2){
                echo "--> Form data (SESSION) <-- <br>";
                print_r ($_SESSION);
            }
            if($dodebug==3){
                echo "--> Form data (SERVER) <-- <br>";
                print_r ($_SERVER);
            }
            if($dodebug==4){
                echo "--> PHP Info <-- <br>";
                phpinfo();
            }
            echo "</pre>";
        }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/Poller.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" --> 
<title>Intranet</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> 
<link href="eng/nsieng.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="images/favicon.ico" > 
</head>
<body bgcolor="#60638D" leftmargin="0" topmargin="0">
<script type="text/javascript" src="scripts/wz_tooltip.js"></script>
<script type="text/javascript" src="scripts/tip_centerwindow.js"></script>
<script type="text/javascript" src="scripts/tip_balloon.js"></script>
<script type="text/javascript" src="scripts/tip_followscroll.js"></script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="254" height="61" align="left" valign="middle"><img src="images/hd1.jpg" width="254" height="61"></td>
    <td align="center" valign="middle" background="images/hd2.jpg"><img src="images/blank header.jpg" width="250" height="61"></td>
    <td width="227" height="61" align="right" background="images/hd2.jpg"><img src="images/blank header.jpg" width="227" height="61"></td>
  </tr>
</table>
</center>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#f2f1df">
  <tr> 
    <td><div align="center">
    <table width="80%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>
                <br>
                <h2 align="center"><strong><font size="+1" face="Georgia, Times New Roman, Times, serif">
                    Manufacturing Price/Cost Analysis Item Charting Utility</font></strong></h2>
                <hr>                
                <form action= <?php echo $_SESSION['http'].$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ?>>
                    <p>
                    <h2 align="center"><strong><font size="+1" face="Georgia, Times New Roman, Times, serif">
                        <?php 
                            if($valid==1) print "2 year Analysis of '".$aitm."' (".$litm.") for Branch: ".$branch;
                        ?>
                    </font></strong></h2>
                    <DIV STYLE='background-color: #FAFAFA; '>
                    <CENTER>
                        <DIV ID='Rendered' STYLE='width: 650px; height: 600px;' ALIGN=Left>
                        <DIV STYLE='font-family: tahoma; color: #808080; font-size: 12px; padding: 15px; padding-top: 5px; padding-bottom: 5px' ALIGN=justify>
                            <B>
                                <?php 
                                    if($valid==1) echo $litm."'s sales history chart";
                                    else echo " ";
                                ?> </B>
                        <BR>
                            <DIV STYLE='border-top: 1px dotted #CCCCCC; height: 16px;'></DIV>
                                <?php if($valid==1){?>
                                To view all sales (SO/ST) of the item from <?php echo "1/1/".$year2 ?> to present, click on -->: 
                                     <A HREF='javascript:render(<?php echo "\"".$litm."\",\"".$branch."\",\"".$hosturl."\"" ?>);' CLASS=InnerFunctionLink>CHART IT!</A>.
                                     <?php //print $render ?>
                                <?php }
                                    elseif ($valid==99) echo "<IMG SRC='images/lightning.png' WIDTH=16 HEIGHT=16> Processing data request, be patient";
                                    else echo "No valid item passed to form, press the back button and try again";
                                ?>
                            <BR><BR>
                            <CENTER>
                                <DIV ID='Rendered' STYLE='width: 650px; height: 600px;' ALIGN=Left>
                                    <DIV ID=Render_1>
                                        <TABLE NOBORDER CELLPADDING=0 CELLSPACING=0 STYLE='margin: 5px;'>
                                            <TR VALIGN=Bottom>
                                                <?php 
                                                    if($valid==99){ print "<TD> </TD>";}
                                                    else { print "<TD WIDTH=20><IMG SRC='images/chart_bar.png' WIDTH=16 HEIGHT=16></TD>";} 
                                                ?>
                                                <TD><?php if($valid==1) echo "To view chart, click on the 'CHART IT!' link above.";?></TD>
                                            </TR>
                                        </TABLE>
                                    </DIV>
                                    <DIV ID='Render_2' STYLE='background-color: #DBFFCF; padding: 4px; display: none;'>
                                        <TABLE NOBORDER CELLPADDING=0 CELLSPACING=0>
                                            <TR VALING=Bottom>
                                                <TD><IMG SRC='images/lightning.png' WIDTH=16 HEIGHT=16></TD>
                                                <TD> The server is processing your request...</TD>
                                            </TR>
                                        </TABLE>
                                    </DIV>
                                    <DIV ID='Render_3' STYLE='display: none;' ALIGN='center'>
                                    </DIV>
                                    <DIV ID=Render_4 STYLE='background-color: #FFCCCC; padding: 4px; display: none;'>
                                        <TABLE NOBORDER CELLPADDING=0 CELLSPACING=0>
                                            <TR VALING=Middle>
                                                <TD><IMG SRC='images/exclamation.png' WIDTH=16 HEIGHT=16></TD>
                                                <TD> The request is taking too much time, remote peer not responding. Try again later.</TD>
                                            </TR>
                                        </TABLE>
                                    </DIV>
                                    <DIV ID='Render_5' STYLE='padding: 4px; display: none;' ALIGN='center'>
                                        <TABLE NOBORDER CELLPADDING=0 CELLSPACING=0 ALIGN=center bgcolor="ffcccc">
                                            <TR><TD>
                                                <?php
                                                    print $rowHead;
                                                    print $rowMonth;
                                                    print $rowDetail;
                                                    print $row1Detail;
                                                    print $row2Detail;
                                                    print $rowFooter;
                                                    //print "<br><strong><font size=+1>Use the Back Button to return to the item Cost Page</font></strong>";
                                                ?>
                                            </TD></TR>
                                        </TABLE>
                                    </DIV>
                                </DIV>
                            </CENTER>
                        </DIV>
                        <?php 
                            //}
                            print $footer;
                        ?>
                    </DIV>
                </form>
            </td>
          </tr>
    </table>
    </td>
  </tr>
</table>
</body>
<SCRIPT>
/* Some global vars definition */
var LoadTries      = 0;
var MaxLoadTries   = 40;
var Preloader      = new Image();
var LoadPic        = new Image();
var URL;

function render(litm,branch,urlhost)
  {
   URL = urlhost+"/litmChart.php";
   //alert('URL: '+URL);
   Preloader.src = URL;
   document.getElementById("Render_1").style.display = "none";
   document.getElementById("Render_3").style.display = "none";
   document.getElementById("Render_4").style.display = "none";
   document.getElementById("Render_5").style.display = "none";
   document.getElementById("Render_2").style.display = "inline";
   LoadTries     = 0;
   setTimeout ("CheckLoadingStatus()", 500);
  }

function CheckLoadingStatus()
  {
   if ( !Preloader.complete )
    {
     LoadTries++;
     if ( LoadTries >= MaxLoadTries )
      {
       document.getElementById("Render_2").style.display = "none";
       document.getElementById("Render_4").style.display = "inline";
      }
     else
      setTimeout ("CheckLoadingStatus()", 500);
    }
   else
    {
     document.getElementById("Render_2").style.display = "none";
     document.getElementById("Render_3").innerHTML="<IMG SRC='"+URL+"' WIDTH=650 HEIGHT=350>";
     document.getElementById("Render_3").style.display = "inline";
     document.getElementById("Render_5").style.display = "inline";
    }
  }
</script>
<!-- InstanceEnd --></html>
<?php
    ob_end_flush();
?>

Here is the litmChart.php page:

<?php
     session_start();
    // Standard inclusions   
    include("pChart/pChart/pData.class");
    include("pChart/pChart/pChart.class");
    $arr = $_SESSION['arr'];//array_fill(1,12,0);
    $arr1 = $_SESSION['arr1'];//array_fill(1,12,0);
    $arr2 = $_SESSION['arr2'];//array_fill(1,12,0);
    $year   = $_SESSION['year'];//date('Y');
    $year1  = $_SESSION['year1'];//$year-1;
    $year2  = $_SESSION['year2'];//$year-2;
    $startjul   =100365+(1000*($year2-2001));
    $endjul = 100365 +(1000*($year1-2000));
    $months = $_SESSION['months'];
    $maxval =$_SESSION['maxval'];
    $litm   =$_SESSION['litm'];
    unset($_SESSION['year']);
    unset($_SESSION['year1']);
    unset($_SESSION['year2']);
    unset($_SESSION['months']);
    unset($_SESSION['arr']);
    unset($_SESSION['arr1']);
    unset($_SESSION['arr2']);
    unset($_SESSION['maxval']);
    unset($_SESSION['litm']);
    // pChart dataset definitions and assignments
    $DataSet = new pData;
    $DataSet->AddPoint($arr,"Year");
    $DataSet->AddPoint($arr1,"Year1");
    $DataSet->AddPoint($arr2,"Year2");
    $DataSet->AddPoint($months,"Month");
    
    //$DataSet->AddSerie("Year1");
    $DataSet->AddAllSeries();
    $DataSet->SetAbsciseLabelSerie("Month");
    $DataSet->SetSerieName("Year: ".$year,"Year");
    $DataSet->SetSerieName("Year: ".$year1,"Year1");
    $DataSet->SetSerieName("Year: ".$year2,"Year2");

    // Initialise the graph
    $Test = new pChart(660,350);
    $Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND);

    // Prepare the graph area
    $Test->setFontProperties("pChart/Fonts/tahoma.ttf",;
    $Test->setGraphArea(90,60,595,300);

    // Initialise graph area
    $Test->setFontProperties("pChart/Fonts/tahoma.ttf",;
    
    // Draw the Item History graph
    $DataSet->SetYAxisName("Quantities");
    $DataSet->SetXAxisName("Period");
    $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
    $Test->drawGraphAreaGradient(40,40,40,-50);
    $Test->drawGrid(4,TRUE,230,230,230,10);
    $Test->setShadowProperties(3,3,0,0,0,30,4);
    $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
    $Test->clearShadow();
    $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
    // Clear the scale
    $Test->clearScale();
  
    // Write the legend (box less)
    $Test->setFontProperties("pChart/Fonts/tahoma.ttf",;
    $Test->drawLegend(530,5,$DataSet->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE);

    // Write the title
    $Test->setFontProperties("pChart/Fonts/MankSans.ttf",18);
    $Test->setShadowProperties(1,1,0,0,0);
    $Test->drawTitle(0,0,"Item Sales History (SO/ST)",255,255,255,660,30,TRUE);
    $Test->clearShadow();

    // Render the picture
    $Test->Render($litm.".png");
    $Test->stroke(); 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.