|
The image ?http:....chart/dbchart.php? cannot be displayed, because it contains errors.?? |
Posted by Marx on May-13-2009 09:53 |
|
Hi
Need your help on this.
Why I was getting an error when I was trying to output a character before the PHP Chart director script?
e.g.
echo "<div id=location>";
include ("chart.php");
echo "</div>";
If I delete the " echo "<div id=location>"; " before the PHP Chart Director script is executed, PHP CD runs normal.
I want to use the " echo "<div id=location>"; " so that I can place and change the location
of the chart anywhere in my page.
The PHP ChartDirector script and PHP-MySQL script are in one file.
I dont want to use the "<IMG SRC="http://aaa.bbb.ccc.ddd/ChartDirector/phpdemo/simplebar.php"> "(as given in you document) because it gives only static chart.
thanks
Marx |
Re: The image ?http:....chart/dbchart.php? cannot be displayed, because it contains errors.?? |
Posted by Peter Kwan on May-14-2009 00:10 |
|
Hi Marx,
I suspect the error is because you are trying to include an image in HTML. It is illegal to include any image in HTML (this is part of the HTML/HTTP standard). For example, in all of your web pages, you cannot include any image. You can include an <IMG> tag (or some other tags), but not the image itself. The image must be loaded from a separate URL.
I suggest you may use an <IMG> tag:
<IMG SRC="http://aaa.bbb.ccc.ddd/ChartDirector/phpdemo/chart.php">
I am not sure why you think the above is a static chart. The above will display the chart is created by "chart.php". If your code "chart.php" creates a dynamic chart, then it is a dynamic chart.
If you are concerned the browser may cache the image (therefore will not access the server to get an updated image), you may code to ask the browser not to use cache. There are many methods as published in various PHP/HTML documentation. The method I use most open is just to append a random number to the URL:
<IMG SRC="http://aaa.bbb.ccc.ddd/ChartDirector/phpdemo/chart.php?random=<?php echo microtime(); ?>">
If you want to pass parameters to "chart.php", you can pass parameters just like passing parameters to any other PHP page. For example, you can use query parameters, cookies, session variables, etc.. An example is:
<IMG SRC="http://aaa.bbb.ccc.ddd/ChartDirector/phpdemo/chart.php?aaa=<?php $param1; ?>&bbb=<?php echo $param2; ?>&random=<?php echo microtime(); ?>">
Hope this can help.
Regards
Peter Kwan |
Re: The image ?http:....chart/dbchart.php? cannot be displayed, because it contains errors.?? |
Posted by Jeff on Dec-04-2013 11:00 |
|
I was wondering if you could give a more concrete example. I am using chartdirector axactly as outlined in your documentation and I am getting nothing but garbled characters for the img. I have provided applicable code below. As you can see, I print_r my arrays to make sure that they are formatted properly. The counter is set to 2 because this is where the data starts.
for($x=2; $x<=$highestRow; $x++){
$valA="A".$x;
//$cellA = "cell".$valA;
$data[$x] = $objPHPExcel->getActiveSheet()->getCell($valA)->getValue();
}
//for loop to assign all B column values to variables
for($x=2; $x<=$highestRow; $x++){
$valB="B".$x;
//$cellB = "cell".$valB;
$labels[$x] = $objPHPExcel->getActiveSheet()->getCell($valB)->getValue();
}
//Create a PieChart object of size 360 x 300 pixels
$c = new PieChart(360, 300);
//Set the center of the pie at (180, 140) and the radius to 100 pixels
$c->setPieSize(180, 140, 100);
//Set the pie data and the pie labels
$c->setData($data,$labels);
print_r($data);
print_r($labels);
//Output the chart
header("Content-type:image/png");
print($c->makeChart2(PNG));
fileUpload.php |
---|
<?php
session_start();
include('includes/fxns.inc.php');
require_once './Classes/PHPExcel.php';
require_once ('./ChartDirector/lib/phpchartdir.php');
$error='';
if (!isset($_SESSION['user'])){
die("<br />You need to login to view this page");
}
$user = $_SESSION['user'];
if(isset($_FILES['xl']['name'])){
$xl=sanitizeString($_FILES['xl']['name']);
if($xl == ''){
$error = "You have not specified a file to upload";
}
$objReader = new PHPExcel_Reader_Excel5();//create new PHPExcel Reader object
$objPHPExcel = $objReader->load($xl);//instantiate our uploaded excel file
$sheetNames=$objPHPExcel->getSheetNames();//get the worksheet names into an array
$objWorksheet = $objPHPExcel->setActiveSheetIndex(1); // set worksheet to second sheet
$highestRow = $objWorksheet->getHighestRow(); //will get total number of rows (will use in the 2 'for loops' below)
//for loop to assign all A column values to variables
for($x=2; $x<=$highestRow; $x++){
$valA="A".$x;
//$cellA = "cell".$valA;
$data[$x] = $objPHPExcel->getActiveSheet()->getCell($valA)->getValue();
}
//for loop to assign all B column values to variables
for($x=2; $x<=$highestRow; $x++){
$valB="B".$x;
//$cellB = "cell".$valB;
$labels[$x] = $objPHPExcel->getActiveSheet()->getCell($valB)->getValue();
}
//Create a PieChart object of size 360 x 300 pixels
$c = new PieChart(360, 300);
//Set the center of the pie at (180, 140) and the radius to 100 pixels
$c->setPieSize(180, 140, 100);
//Set the pie data and the pie labels
$c->setData($data,$labels);
print_r($data);
print_r($labels);
//Output the chart
header("Content-type:image/png");
print($c->makeChart2(PNG));
}
echo <<<_END
<html>
<head><title></title></head>
<body>$error
<form enctype='multipart/form-data' method='POST' action='fileUpload.php'>
Username <input type='file' name='xl' id='xl' value='$user' /><br />
<input type='submit' value='upload' />
</form>
</body>
</html>
_END
?> |
| |
Re: The image ?http:....chart/dbchart.php? cannot be displayed, because it contains errors.?? |
Posted by Peter Kwan on Dec-05-2013 01:55 |
|
Hi Jeff,
If you can see garbage characters, it is likely the code works correctly and a chart image is created. However, you have incorrected inserted the chart image into your HTML web page (which is a violation of the HTTP and HTML standard).
As mentioned in this thread, you cannot include any image in HTML. For example, you cannot copy your JPG image file into a HTML file, or vice versa, so that it becomes a single file. The JPG and HTML should remain as two separated files. What you can do is to put an <IMG> tag in HTML to reference the image file.
The chart is an image. To put it in a HTML web page, please use an <IMG> tag to reference it. Do not copy the charting code to your HTML web page.
The "Direct Database Access" is already a concrete example. Note that in that example, there are two PHP files. The "dbdemo1.php" is responsible for the HTML. It outputs a FORM to accept user input, and it has an <IMG> tag to reference another PHP file "dbdemo1a.php". The "dbdemo1.php" does not containing any charting code at all. The chart is created in "dbdemo1a.php". The "dbdemo1a.php" only creates the chart, but does not output any HTML at all.
For your case, please separate the code into two PHP files - one for the HTML part, and one for the charting part - as similar to the sample code. The HTML part should not have any charting code, and the charting part should have have any HTML output.
Note that you cannot POST from a HTML page to an image page. In the "Direct Database Access" sample code, the HTML page sends the parameters to itself, not to the charting script. It then includes the parameters as query parameters in the <IMG> tag URL, which points to the charting script. In this way, the charting script can obtain the parameters as query parameters.
As the charting cannot contain HTML, please remove all print_r statements from the charting script, as they output HTML and violates the HTTP standard. (According to HTTP standard, each HTTP stream can only contain one MIME type - such as image/png or text/html. It cannot contain both image/png and text/html at the same time.) Please also ensure the files you have included ('includes/fxns.inc.php' and './Classes/PHPExcel.php') does not output text or html. In PHP, anything that is not inside <?php .... ?> is considered as HTML. Even an empty line or space is HTML. So the files 'includes/fxns.inc.php' and './Classes/PHPExcel.php' should not have empty lines or space outside of the <?php .... ?> block.
The above is the simplest case. There are other code structure that does allow you to put the charting code in the HTML part to create the chart (but of course not to output the chart as it violates HTTP and HTML standards). See the "Database Clickable Charts" for an example of such code structure.
Hope this can help.
Regards
Peter Kwan |
|