pChart 2.x forum
http://wiki.pchart.net/forum/

Noob: Can't display charts
http://wiki.pchart.net/forum/viewtopic.php?f=1&t=2289
Page 1 of 1

Author:  ubersoldat [ Wed Nov 30, 2011 3:47 pm ]
Post subject:  Noob: Can't display charts

Hi,

I have started to use pChart2.0 just yesterday, and now i´m learning how to use it.
When I use the example "example.basic.php" included in the files of pChart, everything is ok. So just to learn how to use it, i tried to include it on my code. Just simply add the chart of that example to my php code (at the bottom but with the includes at the beggining).

Well, when i put all of that code up on mine, it works, but the page doesn´t show anything more than the chart. This would be the code. It´s simply a stupid webpage that shows the content of a file in a chart, but i wanted to use charts. So I am triyng to insert it.:

Code:
<?php

/* Include all the classes */
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");


/* Create your dataset object */
$myData = new pData();

/* Add data in your dataset */
$myData->addPoints(array(1,3,4,3,5));

/* Create a pChart object and associate your dataset */
$myPicture = new pImage(700,230,$myData);

/* Choose a nice font */
//$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));

/* Define the boundaries of the graph area */
$myPicture->setGraphArea(60,40,670,190);

/* Draw the scale, keep everything automatic */
$myPicture->drawScale();

/* Draw the scale, keep everything automatic */
$myPicture->drawSplineChart();

/* Render the picture (choose the best way) */
$myPicture->autoOutput("basic.png");




function GetData(){
   $file=fopen("LOG.txt","r");
   
   $lines=0;
   echo "<table border='1' BGCOLOR=#FFFFFF><tr><th>Datei</th><th>Uhr</th><th>Wert</th></td>";
   while(!feof($file)){
         $buff=fgets($file);
         $lines++;
         $Uhr=$buff[7].$buff[8].$buff[9].$buff[10].$buff[11];
         $Datei=$buff[13].$buff[14].$buff[15].$buff[16].$buff[17].$buff[18].$buff[19].$buff[20].$buff[21].$buff[22];
         $Wert=$buff[37].$buff[38].$buff[39].$buff[40].$buff[41];
         
         echo "<tr><td>".$Datei."</td><td>".$Uhr."</td><td>".$Wert."</td></tr>";
   }
   echo "</table><br><br>";

   fclose($file);

}
?>


<html>

<body BACKGROUND="back.jpg">
<center>
<?php
GetData();
?>
</center>

</body>
</html>


When i put the code this way (just want to have the chart printed behing the table I make):

Code:
<?php

/* Include all the classes */
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");






function GetData(){
   $file=fopen("LOG.txt","r");
   
   $lines=0;
   echo "<table border='1' BGCOLOR=#FFFFFF><tr><th>Datei</th><th>Uhr</th><th>Wert</th></td>";
   while(!feof($file)){
         $buff=fgets($file);
         $lines++;
         $Uhr=$buff[7].$buff[8].$buff[9].$buff[10].$buff[11];
         $Datei=$buff[13].$buff[14].$buff[15].$buff[16].$buff[17].$buff[18].$buff[19].$buff[20].$buff[21].$buff[22];
         $Wert=$buff[37].$buff[38].$buff[39].$buff[40].$buff[41];
         
         echo "<tr><td>".$Datei."</td><td>".$Uhr."</td><td>".$Wert."</td></tr>";
   }
   echo "</table><br><br>";

   fclose($file);

}
?>


<html>

<body BACKGROUND="back.jpg">
<center>
<?php
GetData();


?>

</center>
<?
/* Create your dataset object */
$myData = new pData();

/* Add data in your dataset */
$myData->addPoints(array(1,3,4,3,5));

/* Create a pChart object and associate your dataset */
$myPicture = new pImage(700,230,$myData);

/* Choose a nice font */
//$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));

/* Define the boundaries of the graph area */
$myPicture->setGraphArea(60,40,670,190);

/* Draw the scale, keep everything automatic */
$myPicture->drawScale();

/* Draw the scale, keep everything automatic */
$myPicture->drawSplineChart();

/* Render the picture (choose the best way) */
$myPicture->autoOutput("basic.png");
?>

</body>
</html>


It gave´s me this error (as I am working under German Windows):

"Die Grafik "http://localhost/TickerDeltaDebug2/lector2.php" kann nicht angezeigt werden, weil sie Fehler enthält."

It says something like:

"The graphic "http://localhost/TickerDeltaDebug2/lector2.php" can not be displayed because it contains errors."

Commenting the last line: " $myPicture->autoOutput("basic.png");" it works, but, of course, there is no graphic made or displaed.

So, What am i doing wrong?
Thank you for your help.

Author:  ubersoldat [ Wed Nov 30, 2011 4:01 pm ]
Post subject:  Re: Noob: Can't display charts

Well, by now, i have solved the problem with a little "patch". But it´s too far to be a good one i think, cause i don´t use the Stroke function to display the file.

That´s what i changed:

$myPicture->autoOutput("basic.png");

replaced by:

$myPicture->Render("basic.png");

And where i want to display the chart:

<img src="basic.png">

Any other solution?

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/